javascriptxmlnode.jslibxml-js

Append html fragment as node value in libxmljs


I have a libxmljs document in which I would like to append html fragment. For example:

var value = '<div xmlns="http://www.w3.org/1999/xhtml"><p>Soemthing</p></div>';
document.root().node('field', value);

But I would like to preserve html structure. Because after generating xml, inside field I get

 <field>&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;p&gt;Something&lt;/p&gt;&lt;/div&gt;</field>

while I would like to achieve

 <field><div xmlns="http://www.w3.org/1999/xhtml"><p>Something</p></div></field>

I know I can parse htmlFragment but I can't add it afterwards to document. So how to add html fragment? And preserve tags (if they are present)?

Thank you!


Solution

  • I used https://www.npmjs.com/package/xmlbuilder which has raw() method and can be used to insert html as well.