对WhoisAPI进行XML调用

时间:2010-04-14 18:28:39

标签: c# .net xml whois

我刚收到一个帐户:

http://www.whoisxmlapi.com/index.php#/whois-api-doc.php?rid=1

我从未用c#解析XML,我如何获得<email>标签中的信息?

1 个答案:

答案 0 :(得分:1)

我知道三个选项:

XmlDocument示例:

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string email = doc.SelectSingleNode("/WhoisRecord/registrant/email").InnerText;

XmlReader示例:

using (XmlReader reader = new XmlTextReader(new StringReader(xml)))
{
    reader.Read(); 
    reader.ReadStartElement("WhoisRecord");  
    reader.ReadStartElement("registrant");  
    reader.ReadStartElement("email");  
    reader.ReadString().Dump();
}