Skip to content

Recursively add node to child elements #145

Discussion options

You must be logged in to vote

Works with this:

var descendants = doc.descendants.toList();
    for (var i = 0; i < descendants.length; i++) {
      var node = descendants.elementAt(i);

      if (node is xml_parser.XmlText && !node.text.trim().isEmpty) {
        var newNode = xml_parser.XmlElement(xml_parser.XmlName('div'));
        newNode.innerXml = '<span>test</span>';
        node.replace(newNode);
      }
    }

Thanks!

Replies: 3 comments 1 reply

Comment options

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

Comment options

You must be logged in to vote
0 replies
Comment options

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