2012-01-10 9 views
0

私はいくつかの醜いxmlを(もし私が変更することができれば)私に来ることができるように処理する必要があります。 XMLの特定の属性でグループ化して、後で処理したいと考えました。問題は、属性の中にtype = "A"があり、type = "A1"、type = "A2"などのものがあることです。属性タイプ値が "A"一緒にグループ化するサブリングXAttributeの値を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> 

答えて

2

と私はあなたがSubstringの最初の引数として0を渡す必要があることを言うだろう、私の携帯電話でこれを入力し、すなわちSubstring(0,1)

+0

オハイオ州私のおかげで、完全なばかみたいに見えるようになりました。それはまったく感謝しています@afrischke。私はSQLデベロッパーであり、部分文字列の0の位置については考えていません。 – scarpacci

+0

心配しないで、私は自分自身のはるかに恥ずかしい間違いを作った(そして確かにそうするだろう)。 – afrischke

関連する問題