开发者

Add comment nodes outside root with ruby-libxml

开发者 https://www.devze.com 2023-03-30 15:16 出处:网络
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

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


ended up editing the xml string manually to add the comments outside the root node (for both libxml and 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号