0
<test>
<acc id="1"> acc1 </acc>
<acc id="2"> acc2 </acc>
<acc id="3"> acc3 </acc>
<acc id="4"> acc4 </acc>
</test>
ノードますか?子は、例えば、xml属性値
<test>
<acc id="1"> acc1 </acc>
<acc id="2"> acc2 </acc>
<acc id="3"> acc3 </acc>
<acc id="4"> acc4 </acc>
</test>
ノードますか?子は、例えば、xml属性値
あなたは簡単に-XML LINQを-使ってこれを取得することができます: -
XDocument xdoc = XDocument.Load(@"You XML file path");
List<string> result = xdoc.Descendants("acc")
.Select(x => (string)x.Attribute("id")).ToList();
それとも、その後、クエリ構文を好む場合: -
List<int> result2 = (from x in xdoc.Descendants("acc")
select (int)x.Attribute("id")).ToList();
それは動作します。ご協力いただきありがとうございます! –
をあなたが "抽出" を意味しますか? –
両方のクエリを取得するには、var iAccs = xdoc.Descendants( "test")要素( "acc")を選択します(p => new { value =(string)p、 id =(int)p。属性( "id") })。ToList(); – jdweng