使用下列格式写入XML文件中的条目的方法的Xml使用节点
def write_entry(entry)
node = Nokogiri::XML::Node.new("url", @xml_document)
node["loc"]= entry[:url]
node["lastmod"]= entry[:lastmod].to_s
node["changefreq"] = entry[:frequency].to_s
node["priority"] = entry[:priority].to_s
node.to_xml
end
的入口看起来是这样的:
<urlset>
<url loc="http:`enter code here`//www.experteer.co.uk/vacaturebank/banen/vacatures/xing-ag" lastmod="2011-11-23 16:58:27 UTC" changefreq="0.8" priority="monthly"/>
</urlset>
我想XML的条目是这样
<urlset>
<url>
<loc> http://www.experteer.co.uk/vacaturebank/banen/vacatures/xing-ag </loc>
<lastmod> 2011-11-23 16:58:27 UTC </lastmod>
<changefreq> 0.8 </changefreq>
<priority> monthly </priority>
</url>
</urlset>
使用Node或者我必须使用Builder可能吗? 如果可能的话用Node然后怎么样? 如果我必须使用Builder,它会为每个条目写入标题,我如何处理它不为每个条目写入标题。
看看http://stackoverflow.com/questions/3910457/ruby-modify-an-xml-file-in-one-pass – 2011-12-29 12:04:10
这是不同的东西,即时寻找:( – wearybands 2011-12-29 12:22:44