![](/img/trans.png)
[英]Trying to lerp between two point but get NullReferenceException [ unity]
[英]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"
,依此類推。
我的問題是,它僅適用於第一個XElement.
因此,回到第first Xml
。 它僅從cid = 0x158b
的節點打印Children
cid = 0x158b
。 完成該元素后,它將引發NullReferenceException
,並且不會轉到cid = 0x13313
。 為什么會這樣呢?
謝謝!
是。 正如@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));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.