Add child node before other children

83 views
Skip to first unread message

Konstantin Bodnya

unread,
Sep 1, 2014, 7:40:58 AM9/1/14
to libx...@googlegroups.com
So... I'm having a document
<node1>
 
<node3 />
 
<node4 />
 
<node5 />
</node>

So I do
xmlDoc.root().node('node2');

Which will result into
<node1>
 
<node3 />
 
<node4 />  
  <node5 />
 
<node2 />
</node>

How do I insert “node2” before the “node3” with libxmljs?

Thank you very much!

Konstantin Bodnya

unread,
Sep 1, 2014, 7:58:37 AM9/1/14
to libx...@googlegroups.com
Okay... I found it.

We do these things:

newNode = new xmljs.Element(xmlDoc, 'node2');
xmlDoc
.root().child(0).addPrevSibling(newNode);
Reply all
Reply to author
Forward
0 new messages