【问题标题】:How do you extract the user data from the xml and send it to a string?如何从 xml 中提取用户数据并将其发送到字符串?
【发布时间】:2012-07-31 14:39:35
【问题描述】:

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=

等等

【问题讨论】:

    标签: c# twitter oauth


    【解决方案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;
    

    【讨论】:

      【解决方案2】:

      我知道您使用的是 .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;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-17
        • 2018-01-22
        • 2019-05-22
        • 1970-01-01
        • 2011-09-16
        • 2017-07-25
        • 1970-01-01
        相关资源
        最近更新 更多