1

我有从 ARIN 获得的 XML 响应:

<nets xmlns="http://www.arin.net/whoisrws/core/v1" xmlns:ns2="http://www.arin.net/whoisrws/rdns/v1" xmlns:ns3="http://www.arin.net/whoisrws/netref/v2" termsOfUse="https://www.arin.net/whois_tou.html">
    <limitExceeded limit="256">false</limitExceeded>
    <net termsOfUse="https://www.arin.net/whois_tou.html">
        <registrationDate>2003-05-09T16:14:30-04:00</registrationDate>
        <ref>http://whois.arin.net/rest/net/NET-216-113-160-0-1</ref>
        <ns2:delegations termsOfUse="https://www.arin.net/whois_tou.html">
            <ns2:delegationRef name="186.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/186.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="165.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/165.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="173.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/173.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="189.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/189.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="169.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/169.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="167.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/167.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="171.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/171.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="166.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/166.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="190.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/190.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="188.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/188.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="176.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/176.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="172.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/172.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="170.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/170.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="191.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/191.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="174.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/174.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="162.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/162.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="185.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/185.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="180.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/180.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="168.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/168.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="175.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/175.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="161.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/161.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="179.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/179.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="177.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/177.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="183.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/183.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="181.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/181.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="187.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/187.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="163.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/163.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="184.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/184.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="160.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/160.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="182.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/182.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="178.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/178.113.216.in-addr.arpa.</ns2:delegationRef>
            <ns2:delegationRef name="164.113.216.in-addr.arpa.">http://whois.arin.net/rest/rdns/164.113.216.in-addr.arpa.</ns2:delegationRef>
        </ns2:delegations>
        <endAddress>216.113.191.255</endAddress>
        <handle>NET-216-113-160-0-1</handle>
        <name>EBAY-QA-IT-1</name>
        <netBlocks>
            <netBlock>
                <cidrLength>19</cidrLength>
                <endAddress>216.113.191.255</endAddress>
                <description>Direct Assignment</description>
                <type>DS</type>
                <startAddress>216.113.160.0</startAddress>
            </netBlock>
        </netBlocks>
        <pocs termsOfUse="https://www.arin.net/whois_tou.html"/>
        <orgRef name="eBay, Inc" handle="EBAY">http://whois.arin.net/rest/org/EBAY</orgRef>
        <parentNetRef name="NET216" handle="NET-216-0-0-0-0">http://whois.arin.net/rest/net/NET-216-0-0-0-0</parentNetRef>
        <startAddress>216.113.160.0</startAddress>
        <updateDate>2012-03-02T08:03:18-05:00</updateDate>
        <version>4</version>
    </net>
</nets>

我正在尝试获取此信息:

http://whois.arin.net/rest/org/EBAY

从这一行:

<orgRef name="eBay, Inc" handle="EBAY">http://whois.arin.net/rest/org/EBAY</orgRef>

如何使用 C# 获取此信息?

4

3 回答 3

7

使用 Linq-Xml(在 .Net 3.5 及更高版本中可用),您可以使用以下代码片段来完成:

XNamespace xns = "http://www.arin.net/whoisrws/core/v1"; //The default xmlns from the root element.

var orgRefHandle =
  XDocument.Parse(xml)
  .Root
  .Element(xns + "net")
  .Element(xns + "orgRef")
  .Attribute("handle").Value;
于 2012-10-09T22:39:57.077 回答
4

一种方法是使用XmlDocument

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);

foreach(XmlElement ele in xmlDoc.DocumentElement.GetElementsByTagName("net"))
{
    // Writes value to console.
    Console.WriteLine(((XmlElement)ele.GetElementsByTagName("orgRef")).Attributes["handle"].Value);
}
于 2012-10-09T22:40:28.487 回答
0

将内容加载到 XmlDocument 中,然后您可以使用 XPath 查询使用 SelectSingleNode: 获取节点的属性/nets/limitexceeded/net/orgref/@Name并获取值。

于 2012-10-09T22:40:44.127 回答