2012-04-26 53 views
1

Nokogiri如何将节点对象内容插入到XML :: Builder结构中?Nokogiri如何将节点对象内容插入到XML :: Builder结构中?

#source nodes 
mynodes = [...array of Nodes...] 

#where I want to dump source nodes 
target_for_nodes = somebuilder.doc.xpath('//mydoc/mynodecollection').first 

#drop the nodes into place 
Nokogiri::XML::Builder.with(target_for_nodes) do |xml| 
    mynodes.each do |node| 
    xml.text node.to_xml #gives escaped text- how to drop real XML here from the Node? 
    end 
end 

它给出了转义的文本,但它并不清楚如何从Node对象中删除真正的XML在这里?

+0

您应该接受更多答案,您的费率很低。 – 2012-05-11 02:13:00

回答

4

嗯。看来我只需要使用

xml << node.to_xml 

而不是

xml.text node.to_xml 

干杯!

+2

阅读文档时可以找到的结果是完全令人惊讶的。 – fooledbyprimes 2012-04-26 15:32:45

相关问题