LINQ を使用して特定の属性値を持つ特定の要素を見つけ、別の属性値を返そうとしています。探している要素の名前を一意のものに変更して検索すると、正しい値が返されます。残念ながら、私は XML 形式を制御できないため、これをライブで行うことはできません。したがって、LINQ に各要素の「行」を通過させ、探している属性を返す方法を教えてください。
編集: エラーは null 参照です
XML (サンプル):
<currentTime>2013-01-31 12:34:49</currentTime>
<result>
<rowset name="kills" key="killID" columns="killID,solarSystemID,killTime,moonID">
<row killID="28024540" solarSystemID="30000967" killTime="2013-01-25 21:41:00" moonID="0">
<victim characterID="888493667" characterName="Syrsyrian" corporationID="98152004" corporationName="Eviscerate." allianceID="0" allianceName="" factionID="0" factionName="" damageTaken="20220" shipTypeID="4306" />
<rowset name="attackers" columns="characterID,characterName,corporationID,corporationName,allianceID,allianceName,factionID,factionName,securityStatus,damageDone,finalBlow,weaponTypeID,shipTypeID">
<row characterID="1062593035" characterName="cal dasiri" corporationID="310281086" corporationName="Un4seen Development" allianceID="1566707582" allianceName="Republic Alliance" factionID="0" factionName="" securityStatus="5.00586641950613" damageDone="2286" finalBlow="1" weaponTypeID="2629" shipTypeID="24698" />
<row characterID="0" characterName="" corporationID="98074388" corporationName="The New Lunar Republic" allianceID="0" allianceName="" factionID="0" factionName="" securityStatus="0" damageDone="9620" finalBlow="0" weaponTypeID="0" shipTypeID="17404" />
<row characterID="584494552" characterName="Diesel24" corporationID="753753190" corporationName="Space-Bar" allianceID="1566707582" allianceName="Republic Alliance" factionID="0" factionName="" securityStatus="3.5" damageDone="2322" finalBlow="0" weaponTypeID="24702" shipTypeID="24702" />
<row characterID="90905050" characterName="Thomas Shaefer" corporationID="187930037" corporationName="The Partisan Brigade" allianceID="1566707582" allianceName="Republic Alliance" factionID="0" factionName="" securityStatus="4.1" damageDone="1940" finalBlow="0" weaponTypeID="27315" shipTypeID="16227" />
<row characterID="624484955" characterName="Full Penetration" corporationID="187930037" corporationName="The Partisan Brigade" allianceID="1566707582" allianceName="Republic Alliance" factionID="0" factionName="" securityStatus="3.1" damageDone="1788" finalBlow="0" weaponTypeID="27371" shipTypeID="16227" />
<row characterID="1695597027" characterName="Algazi" corporationID="187930037" corporationName="The Partisan Brigade" allianceID="1566707582" allianceName="Republic Alliance" factionID="0" factionName="" securityStatus="1.5" damageDone="1258" finalBlow="0" weaponTypeID="1818" shipTypeID="24698" />
<row characterID="92087835" characterName="Yasin Stavrouski" corporationID="310281086" corporationName="Un4seen Development" allianceID="1566707582" allianceName="Republic Alliance" factionID="0" factionName="" securityStatus="0.4" damageDone="561" finalBlow="0" weaponTypeID="8819" shipTypeID="587" />
<row characterID="581357145" characterName="Nykitah" corporationID="187930037" corporationName="The Partisan Brigade" allianceID="1566707582" allianceName="Republic Alliance" factionID="0" factionName="" securityStatus="5" damageDone="445" finalBlow="0" weaponTypeID="24702" shipTypeID="24702" />
<row characterID="92692957" characterName="Mokey PYD" corporationID="98153124" corporationName="Plots Your Demise" allianceID="0" allianceName="" factionID="0" factionName="" securityStatus="0" damageDone="0" finalBlow="0" weaponTypeID="5399" shipTypeID="594" />
<row characterID="90511370" characterName="Rae'll" corporationID="187930037" corporationName="The Partisan Brigade" allianceID="1566707582" allianceName="Republic Alliance" factionID="0" factionName="" securityStatus="-0.4" damageDone="0" finalBlow="0" weaponTypeID="527" shipTypeID="670" />
</rowset>
<rowset name="items" columns="typeID,flag,qtyDropped,qtyDestroyed,singleton">
<row typeID="3090" flag="31" qtyDropped="0" qtyDestroyed="1" singleton="0" />
<row typeID="31564" flag="94" qtyDropped="0" qtyDestroyed="1" singleton="0" />
そしてクエリ:
XAttribute two = (from kd1 in loadkillData1.Elements("row")
where (string)kd1.Attribute("characterName") == "cal dasiri"
select kd1.Attribute("allianceName")).FirstOrDefault();
string derp2 = two.Value;
label10.Content = derp2;