0
我試圖抓住一個屬性的具體數值:C#XmlDocument用於獲取API特定數據?
http://data.alexa.com/data?cli=10&dat=snbamz&url=bing.com
<SD>
<POPULARITY URL="bing.com/" TEXT="16" SOURCE="panel"/>
<REACH RANK="16"/>
<RANK DELTA="-7"/>
<COUNTRY CODE="US" NAME="United States" RANK="9"/>
</SD>
</ALEXA>
我要搶我當前控制檯代碼這個的
值:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string url = "http://data.alexa.com/data?cli=10&dat=snbamz&url=bing.com";
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(url);
XmlNode root = xmldoc.SelectSingleNode("//@RANK");
//XmlNamespaceManager xnm1 = new XmlNamespaceManager(xmldoc.NameTable);
//XmlNodeList nList1 = xmldoc.SelectNodes("//@RANK", xnm1);
Console.WriteLine(root.ToString());
Console.ReadLine();
}
}
}
但是當我運行它時,我會收到以下消息:
System.Xml.XmlAttribute
我在做什麼錯?
工作完美..非常感謝你! – rodvaN
如果您將我的答案標記爲已接受,我將不勝感激。 –