0
我有一些丑陋的XML(如果我可以改变我会)来找我,我需要能够处理。我想通过XML中的特定属性进行分组以供进一步处理。问题是某些属性的type =“A”,有些属于type =“A1”,type =“A2”等。我想要所有具有以“A”开头的属性类型值的元素,被分组在一起。我怎么能从LINQ子串字符串属性值
这不是工作,我不知道是什么改变来得到它的工作:
var result = from ele in xdoc.Descendants(Namespace + "item")
let item= ele.Attribute("type").Value.Substring(1,1)
group ele by item into grp
select grp;
当我脱下它工作正常的子字符串,但显然不组我多么希望。
错误:
Error has been thrown by the target of an invocation
示例XML:
<items>
<item type="A" position="0">
<itemvalue>10</itemvalue>
</item>
<item type="A1" position="1">
<itemvalue>20</itemvalue>
</item>
<item type="A2" position="2">
<itemvalue>30</itemvalue>
</item>
<item type="B" position="0">
<itemvalue>10</itemvalue>
</item>
<item type="B1" position="1">
<itemvalue>20</itemvalue>
</item>
<item type="B2" position="2">
<itemvalue>30</itemvalue>
</item>
</items>
哦,我的天哪,感谢让我看起来像一个完全白痴......这完全是谢谢@afrischke。我是一名sql开发人员,甚至没有考虑子字符串中的0位置。 – scarpacci 2012-01-10 17:22:11
不要担心,我已经(当然会造成)自己更尴尬的错误。 – afrischke 2012-01-10 23:34:17