开发者

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜