加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET从网站读取外部XML

发布时间:2020-12-16 09:32:00 所属栏目:asp.Net 来源:网络整理
导读:我想读一个位于 here的XML文件 数据看起来像这样 profile steamID6476561197967256555/steamID64 steamID![CDATA[snivfbo]]/steamID onlineStateoffline/onlineState stateMessage![CDATA[]]/stateMessage privacyStateprivate/privacyState visibilityState
我想读一个位于 here的XML文件

数据看起来像这样

<profile> 
    <steamID64>76561197967256555</steamID64> 
    <steamID><![CDATA[snivfbo]]></steamID> 
    <onlineState>offline</onlineState> 
    <stateMessage><![CDATA[]]></stateMessage> 
    <privacyState>private</privacyState> 
    <visibilityState>1</visibilityState> 
    <avatarIcon><![CDATA[http://media.steampowered.com/steamcommunity/public/images/avatars/9d/9d13f8f8061b7adaa9e9c2766e2bb2b3d82f911c.jpg]]></avatarIcon> 
    <avatarMedium><![CDATA[http://media.steampowered.com/steamcommunity/public/images/avatars/9d/9d13f8f8061b7adaa9e9c2766e2bb2b3d82f911c_medium.jpg]]></avatarMedium> 
    <avatarFull><![CDATA[http://media.steampowered.com/steamcommunity/public/images/avatars/9d/9d13f8f8061b7adaa9e9c2766e2bb2b3d82f911c_full.jpg]]></avatarFull> 
    <vacBanned>0</vacBanned> 
    <isLimitedAccount>0</isLimitedAccount> 
</profile>

而我只是希望能够访问这些值.我对XmlTextReaders的了解有限,这让我无处可去.谢谢.

解决方法

XDocument doc = XDocument.Load("http://steamcommunity.com/profiles/76561197967256555/?xml=1");
        string steamID64 = doc.Root.Descendants("steamID64").First().Value;
        string steamID = doc.Root.Descendants("steamID").First().Value;
        string onlineState = doc.Root.Descendants("onlineState").First().Value;
        string stateMessage = doc.Root.Descendants("stateMessage").First().Value;
        string privacyState = doc.Root.Descendants("privacyState").First().Value;
        string visibilityState = doc.Root.Descendants("visibilityState").First().Value;
        string avatarIcon = doc.Root.Descendants("avatarIcon").First().Value;
        string avatarMedium = doc.Root.Descendants("avatarMedium").First().Value;
        string avatarFull = doc.Root.Descendants("avatarFull").First().Value;
        string vacBanned = doc.Root.Descendants("vacBanned").First().Value;
        string isLimitedAccount = doc.Root.Descendants("isLimitedAccount").First().Value;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读