Add comment nodes outside root with ruby-libxml

I am writing xml exporter in ruby ​​and I am using the libxml package for it. I want to write some comment nodes outside the root element

<?xml version="1.0" encoding="UTF-8"?> <!-- comment --> <root> <childnode /> </root> 

How to export to a higher format?

Sample ruby ​​code to generate the above (ignoring the node comment)

 doc = XML::Document.new() rootNode = XML::Node.new('root') doc.root = rootNode childNode = XML::Node.new('childnode') childnode << rootNode 
+4
source share
2 answers

finished editing the xml line manually to add comments outside the root node (for libxml and nokogiri

0
source
 <?xml version="1.0" encoding="UTF-8" ?> <List type = "" ="00:75:00" ="00:00:05"> </List> 

Yes

 <?xml version="1.0" encoding="UTF-8" ?> <List type = "update" > </List> 
-2
source

Source: https://habr.com/ru/post/1369008/


All Articles