2012-08-02 53 views

回答

1

像這樣的事情可能?

XDocument doc = XDocument.Parse("<insert xml here or use variable>"); 
var username = doc.XPathSelectElement("/SomeNode/SomeOtherNode/@username").Value; 
var id = doc.XPathSelectElement("/SomeNode/SomeOtherNode/@id").Value; 
1

我知道你正在使用.NET 2.0,所以我在這個例子中使用的XmlDocument:

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); 
TwitterUser user = new TwitterUser(); 

string url = "http://api.twitter.com/1/account/verify_credentials.xml"; 
string xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty); 

xmlDoc.LoadXml(xml); 

user.id = xmlDoc.SelectSingleNode("user/id").InnerText; 
user.screen_name = xmlDoc.SelectSingleNode("user/screen_name").InnerText; 
user.name = xmlDoc.SelectSingleNode("user/name").InnerText; 
相關問題