简体   繁体   中英

Add comment nodes outside root with ruby-libxml

I am writing an xml exporter in ruby and I am using 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 do I accomplish export to above format?

Sample ruby code to generate the above (without accounting for comment node)

doc = XML::Document.new()
rootNode = XML::Node.new('root')
doc.root = rootNode
childNode = XML::Node.new('childnode')
childnode << rootNode

最终手动编辑xml字符串以在根节点外部添加注释(对于libxml和nokogiri而言)

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM