[英]ruby xpath nokogiri
I am using nokogiri ruby gem to parse xml. 我正在使用nokogiri ruby gem解析xml。
<d:abc>19</d:abc>
<d:def m:type="Edm.Double">0</**d:def>
Assuming entry is XML Nokogiri node, using sample xml above. 假设条目是XML Nokogiri节点,使用上面的示例xml。 I could easily get the text of abc by using entry.xpath('d:abc').text 我可以通过使用entry.xpath('d:abc')。text轻松获得abc的文本
How to get the text of def ? 如何获得def的文本?
Thanks 谢谢
require 'nokogiri'
xml = Nokogiri::XML('<root xmlns:m="bar"><def m:type="Edm.Double" /></root>')
p xml.at_xpath('//def').attribute('type').text
#=> "Edm.Double"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.