【发布时间】:2010-04-13 14:14:02
【问题描述】:
好的,有点随机的问题,但最好的方法是添加代码,您将能够立即明白我的意思:
XML:
<?xml version="1.0" encoding="utf-8" ?>
<customers>
<customer>
<id>1</id>
<name>Blah-face</name>
<Type>1</Type>
</customer>
<customer>
<id>2</id>
<name>Blah-face-2</name>
<Type>2</Type>
</customer>
<customer>
<id>3</id>
<name>Blah-face-3</name>
<Type>1</Type>
<SuperType>1</SuperType>
</customer>
</customers>
C#:
XDocument linquee = XDocument.Load(path);
var superType = (from c in linquee.Descendants("customer")
where (c.Element("SuperType").Value == "1")
select c).ToList();
这会出现一个空错误 - 我是否需要在每个客户之前添加一个带有空值的“SuperType”元素,或者是否有一种解决方法意味着我不必这样做?
干杯!
【问题讨论】:
标签: c# xml linq linq-to-xml