gpt4 book ai didi

c# - 读取奇怪的 XML 文件

转载 作者:太空宇宙 更新时间:2023-11-03 20:12:25 24 4
gpt4 key购买 nike

我通过这个网站和谷歌进行了搜索,并没有真正找到与此类似的任何东西..因为我遇到的大多数例子都是更正常、更清晰的标准?我只需要弄清楚如何读取 Name=、Handle= 和 Tweet=。感谢您的帮助

到目前为止我只有这个:

doc = XDocument.Load("twitterTrio.xml");    
var temp = doc.Descendants("tweets")....

我正在尝试读取的 xml:

<?xml version="1.0" encoding="utf-8"?>
<dtvTwitter>
<tweets>
<RcsTweet xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="NFL on ESPN" Handle="@ESPNNFL" Tweet="So @RGIII can pass, run and now he can BEAT BOX?? (MUST SEE VIDEO) --&gt; http://t.co/sexsrtskfZ" ImageUrl="http://a0.twimg.com/profile_images/3573179175/26a4fd77256691aedab2ecbc60c7b86c_normal.jpeg" />
<RcsTweet xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="NFL Retweet" Handle="@NFLRT" Tweet="RT @NOTSportsCenter: BREAKING: There's a reason #Jets coach Rex Ryan keeps naming Mark Sanchez starter: he's blind. http://t.co/zEPKqfAV1o" ImageUrl="http://a0.twimg.com/profile_images/378800000203929393/ef2529f3f226d69c0731c7469f1c51ba_normal.jpeg" />
<RcsTweet xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="ProFootballTalk" Handle="@ProFootballTalk" Tweet="Bernard Pollard says Justin Hunter can destroy a defense, be a star and help the Titans win a championship http://t.co/GPJcJXXqvg" ImageUrl="http://a0.twimg.com/profile_images/2390753568/qzhbfg9lgfrkmkrt4l4u_normal.jpeg" />
</tweets>
</dtvTwitter>

最佳答案

    XmlNodeList elemList = doc.GetElementsByTagName("RcsTweet");
for (int i = 0; i < elemList.Count; i++)
{
string name = elemList[i].Attributes["Name"].Value;
string handle = elemList[i].Attributes["Handle"].Value;
string tweet = elemList[i].Attributes["Tweet"].Value;
}

关于c# - 读取奇怪的 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19170698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com