XMLReader的穿越节点 [英] xmlreader traversing nodes
本文介绍了XMLReader的穿越节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XML文件,如下所示,
I have an xml file as follows,
<rss>
<report name="rpt1">
<title>AAA</title>
<image/>
<weblink/>
<pdflink/>
<pdfsize/> </report>
<report name="rpt2">
<title>BBB</title>
<image/>
<weblink/>
<pdflink/>
<pdfsize/> </report>
</rss>
我要遍历的链接,并转到报告节点,并拿到冠军/图像/网站链接/ pdflink /每个报告pdfsize。我怎样才能做到这一点使用XML阅读器。我谷歌和看穿越单个节点,但不是在循环。任何投入?
I have to traverse the link and goto report nodes and get the title/image/weblink/pdflink/pdfsize for each reports. How can i do that using xml reader. I google and see traversing for a single node but not in loop. any inputs?
推荐答案
您可以使用的 LINQtoXML 摆脱YOUT XML的项目。
You can use LINQtoXML to get the items from yout XML.
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
}
}
这篇关于XMLReader的穿越节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文