开发者

Ruby Hpricot XML Parsing ARIN document

I am trying to parse this ARIN xml document. I want to get the "name" attribute inside the orgRef tag, and it's not doing what I expected when I parse it with Hpricot

<?xml version='1.0'?><?xml-stylesheet type='text/xsl' href='http://whois.arin.net/xsl/website.xsl' ?><nets xmlns="http://www.arin.net/whoisrws/core/v1" xmlns:ns2="http://www.arin.net/whoisrws/rdns/v1" termsOfUse="https://www.arin.net/whois_tou.html"><limitExceeded limit="256">false</limitExceeded><net termsOfUse="https://www.arin.net/whois_tou.html"><registrationDate>1998-04-18T00:00:00-04:00</registrationDate><ref>http://whois.arin.net/rest/net/NET-205-188-0-0-1</ref><ns2:delegations termsOfUse="https://www.arin.net/whois_tou.html"><ns2:delegationRef name="188.205.in-addr.arpa.">http://whois.arin.net/rest/rdns/188.205.in-addr.arpa.</ns2:delegationRef></ns2:delegations><endAddress>205.188.255.255</endAddress><handle>NET-205-188-0-0-1</handle><name>AOL-DTC</name><netBlocks><netBlo开发者_JS百科ck><cidrLength>16</cidrLength><endAddress>205.188.255.255</endAddress><description>Direct Assignment</description><type>DS</type><startAddress>205.188.0.0</startAddress></netBlock></netBlocks><pocs termsOfUse="https://www.arin.net/whois_tou.html"><pocLinkRef handle="AOL-NOC-ARIN" function="T" description="Tech">http://whois.arin.net/rest/poc/AOL-NOC-ARIN</pocLinkRef></pocs><orgRef name="America Online, Inc" handle="AMERIC-59">http://whois.arin.net/rest/org/AMERIC-59</orgRef><parentNetRef name="NET205" handle="NET-205-0-0-0-0">http://whois.arin.net/rest/net/NET-205-0-0-0-0</parentNetRef><startAddress>205.188.0.0</startAddress><updateDate>1998-04-27T00:00:00-04:00</updateDate><version>4</version></net></nets>

I am doing this:

doc = Hpricot(contents)
(doc/:orgRef).each do |orefRef|
    puts  "FOUND ELEMENT!"   
end

When I do (doc/:net), it is outputting something, but for some reason it can't find that single element. Any ideas. I try (doc/:net/orgRef) as well. What's up? Did ARIN purposely made this XML impossible to parse?


Never mind. I got it. I had to do ipWebHost = (doc/"net/orgRef")[0]['name']

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜