使用Nokogiri如何将Node对象内容插入XML::Builder结构中



使用Nokogiri,如何将Node对象内容插入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

它给出了转义的文本,但我不清楚如何将真正的 XML 从 Node 对象中删除到此处?

嗯。看来我只需要使用

xml << node.to_xml 

而不是

xml.text node.to_xml

干杯!

最新更新