Skip to content

Taking a child XmlElement, removing it and wrapping it around its parent #168

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

You must be logged in to vote

This works for me:

final actual = XmlDocument.parse('<XML><BOX><IMG><BLUR /><URL value="./" /></IMG></BOX></XML>');
final image = actual.findAllElements('IMG').single;
final blur = image.findAllElements('BLUR').single;
image.children.remove(blur);
image.replace(blur);
blur.children.add(image);
final expected = XmlDocument.parse('<XML><BOX><BLUR><IMG><URL value="./" /></IMG></BLUR></BOX></XML>');
expect(expected.toXmlString(), actual.toXmlString());

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BrayFlex
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