0

次のようなxmlファイルがあります。

<rss> 
<report name="rpt1"> 
<title>AAA</title> 
<image/> 
<weblink/> 
<pdflink/> 
<pdfsize/> </report> 
<report name="rpt2"> 
<title>BBB</title> 
<image/> 
<weblink/> 
<pdflink/> 
<pdfsize/> </report> 
</rss>

リンクをたどってレポート ノードに移動し、各レポートの title/image/weblink/pdflink/pdfsize を取得する必要があります。xmlリーダーを使用してそれを行うにはどうすればよいですか。グーグルで検索すると、単一のノードのトラバースが見られますが、ループではありません。入力はありますか?

4

1 に答える 1

1

LINQtoXMLを使用して、 youtXMLからアイテムを取得できます。

var path = Server.MapPath("~/Content/pairs.xml");    
XElement elm = XElement.Load(path);
//you can also load the XML from stream / string also

if (elm != null)
{
    foreach (var item in elm.Elements("report"))
    {
        string title = item.Element("title").Value;
        string image = item.Element("image").Value;
        string weblink= item.Element("weblink").Value;
        //do whatever with the values          
    }
}
于 2012-08-08T20:11:20.797 に答える