Skip to content

Insert node in the xml file directly #129

Answered by renggli
mitien asked this question in Q&A
Discussion options

You must be logged in to vote

Sure, something along those lines should work:

final document = XmlDocument.parse(input);
final mainNode = document.findAllElements('mainNode').first;
final lastItemNode = mainNode.findAllElements('item').last;
final lastItemIndex = mainNode.children.indexOf(lastItemNode);
final builder = XmlBuilder();
builder.element('item',
     attributes: {'name': 'Text4'},
     nest: () => builder.element('dataValue', nest: 4));
mainNode.children.insert(lastItemIndex + 1, builder.buildFragment());
final output = document.toXmlString();

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@mitien
Comment options

Answer selected by mitien
Comment options

You must be logged in to vote
3 replies
@mitien
Comment options

@renggli
Comment options

@mitien
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants