【发布时间】:2012-05-27 14:44:13
【问题描述】:
<Peoples>
<People>
<Name>RadheyJang</Name>
<Location>India</Location>
<Work>Software Developer</Work>
<Point>5</Point>
<details>
<People>
<Name>ArunaTiwari</Name>
<Location>India</Location>
<Work>SoFtwareCoder</Work>
<Point>3</Point>
<details/>
<Test>A</Test>
</People>
</details>
<Test>NA</Test>
</People>
</Peoples>
我可以通过使用下面的代码来阅读那个 Xml。
XDocument xmlDoc = XDocument.Load(str);
var vrresult = from a in xmlDoc.Descendants("People")
select new
{
Name= a.Element("Name").Value,
Location= a.Element("Location").Value,
Point= a.Element("Point").Value
};
GridView1.DataSource = vrresult;
GridView1.DataBind();
但它也在阅读详细信息的内容。我想跳过阅读 details 元素内的内容。请让我知道如何跳过详细信息中的内容。
【问题讨论】:
-
我以前从未见过该错误消息...您能否编辑您的答案并添加 GridView 标记以及绑定您的 XML 的代码?
-
Gridview 绑定没有问题。我会在阅读时绑定但在绑定之前它给出错误。
-
啊,明白了。我没有给你答案,但也许这个链接会有所帮助:dotnet247.com/247reference/msgs/5/26129.aspx
-
像您在此处所做的那样更改问题的内容被认为是不好的做法。第一次编辑是您收到的错误消息。然后您将其更改为“如何阅读某些内容..”。下一次,打开一个新问题。
-
请问为什么要跳过详细内容?无论如何,您都需要阅读它以了解详细信息标签的结束位置(以便阅读 xml 文件的其余部分)。您想在这里实现什么目标?