简体   繁体   中英

ruby xpath nokogiri

I am using nokogiri ruby gem to parse 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. I could easily get the text of abc by using entry.xpath('d:abc').text

How to get the text of 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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM