1

このサイトとグーグルで検索しましたが、これに似たものは実際には見つかりませんでした..私が遭遇したほとんどの例は、より正常でクリーンな標準のものですか? 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>
4

2 に答える 2

3
    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;
    }
于 2013-10-03T23:21:19.077 に答える
2

私は通常、XML シリアライゼーションを使用し、.Net に予期しないケースを処理させることを好みます。

public class dtvTwitter
{
    public tweets tweets{get;set;}
}
public class tweets
{
    [XmlElement("RcsTweet")]
    public List<RcsTweet> RcsTweets { get; set; }

}
public class RcsTweet
{
    [XmlAttribute]
    public string Name { get; set; }

    [XmlAttribute]
    public string Tweet { get; set; }

    [XmlAttribute]
    public string Handle { get; set; }
}

それからちょうど:

        XmlSerializer ser = new XmlSerializer(typeof(dtvTwitter));
        StreamReader sr = new StreamReader("myfile.xml");
        dtvTwitter val = (dtvTwitter)ser.Deserialize(sr);

逆シリアル化されたグラフを取得するには

于 2013-10-04T00:30:09.447 に答える