主要文章 https://www.engineyard.com/blog/2010/getting-started-with-nokogiri/ 还有
http://nokogiri.rubyforge.org/nokogiri/Nokogiri.html
这样就创建了一个新的节点,名字是otherElement,有一个属性是foo,值是newAttributeValue。再把它加到el中。再加上Nokogiri::XML::Text.new("bar"), doc)创建文本节点,就可以传见任意属性和内容的节点了。
http://nokogiri.rubyforge.org/nokogiri/Nokogiri.html
doc = Nokogiri::XML::Document.parse(File.open("myfile.xml"))
el = doc.at_xpath('//foo:element')
newEl = Nokogiri::XML::Node.new("otherElement", doc)
newEl["foo"] = "newAttributeValue"
el.add_child(newEl)
这样就创建了一个新的节点,名字是otherElement,有一个属性是foo,值是newAttributeValue。再把它加到el中。再加上Nokogiri::XML::Text.new("bar"), doc)创建文本节点,就可以传见任意属性和内容的节点了。