-2

http://www.voiceoftech.com/swhitley/index.php/2009/03/twitter-oauth-with-net/

url = "http://twitter.com/account/verify_credentials.xml";
xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
apiResponse.InnerHtml = Server.HtmlEncode(xml);

如何从 xml 中提取用户数据并将其发送到字符串?即将xml转换为字符串。

string name =
string id=

等等

4

2 回答 2

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;
于 2012-08-02T16:55:30.370 回答
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;
于 2012-08-02T15:26:44.457 回答