提问人:Luis Lavieri 提问时间:7/12/2014 更新时间:7/12/2014 访问量:47
尝试在两个 Xml 文档之间执行联接时出现 NullReferenceException
NullReferenceException when trying to do a Join between two Xml Documents
问:
我有一个看起来像这样的文档(它包含显示的更多父母和孩子):Xml
<item cid="0x12e3">
<item cid="0x1310">
<item cid="0x158b">
<item luid="2001"/>
<item luid="2002"/>
</item>
<item cid="0x13313">
<item luid="2001"/>
<item luid="2002"/>
</item>
...
</item>
</item>
我还有一个具有如下属性的文档:Xml
<?xml version="1.0" encoding="UTF-8"?>
<EditorRule>
<Properties>
<Property name="Comment" luid="2001"/>
...
</Properties>
</EditorRule>
现在,我正在两个文件之间做一个 从 在:Join
Select
XElements
first xml
Second xml
(from element in Element.Elements().Elements().Elements()
join property in propertiesFromFile on element.Attribute("luid").Value equals property.Luid
select new IpjItem(element));
这工作正常,当我迭代它时,它会打印等等。IEnumerable
Name="Comment"
我的问题是它只适用于第一个 所以,回到.它只打印带有 的 from the Node 的 。在完成该元素后,它会抛出 并且不会转到带有 .为什么会这样?XElement.
first Xml
Children
cid = 0x158b
NullReferenceException
cid = 0x13313
谢谢!
答:
0赞
Luis Lavieri
7/12/2014
#1
是的。正如令人震惊的那样,我的问题出在.此外,我还添加了一个更好的子句来检查该属性是否存在。@Selman22
Element.Elements()
Where
return (from element in Element.Elements()
where element.Attribute("luid") != null
join property in RuleEditorXml.Properties on element.Attribute("luid").Value equals property.Luid
select new IpjItem(element, Parent));
评论
Element.Elements().Elements().Elements()
!?