的XML響應我有結構如下的XML響應:迭代IN C#
<e:Parents>
<d1p1:Parent>
<d1p1:Name>A</d1p1:Name>
<d1p1:Child>a1</d1p1:Child>
<d1p1:Id>101</d1p1:Id>
</d1p1:Parent>
<d1p1:Parent>
<d1p1:Name>A</d1p1:Name>
<d1p1:Child>a2</d1p1:Child>
<d1p1:Id>102</d1p1:Id>
</d1p1:Parent>
<d1p1:Parent>
<d1p1:Name>B</d1p1:Name>
<d1p1:Child>b1</d1p1:Child>
<d1p1:Id>201</d1p1:Id>
</d1p1:Parent>
<d1p1:Parent>
<d1p1:Name>B</d1p1:Name>
<d1p1:Child>b2</d1p1:Child>
<d1p1:Id>202</d1p1:Id>
</d1p1:Parent>
</e:Parents>
現在基於給定的輸入(例如,A a2)的我需要來獲取ID(例如102)。
在我的功能我想使用的東西這樣
int getId(string str) // str = A a2
{
int index = str.IndexOf(' ');
string p = str.Substring(0, index); //A
string c = str.Substring(index); //a2
var parent = response.Parents.FirstOrDefault(e => e.Name == p && e.Child == c);
return parent.Id;
}
它給了我這說的錯誤:
「的類型參數的方法「System.Linq.Enumerables.FirstOrDefault(系統.Collections.Generics.IEnumerable,System.Func)'不能根據用法推斷,請嘗試明確指定參數。「
我需要知道如何獲得基於父母和孩子的ID。
你看着'XPath'? – user1 2015-03-31 16:15:26
不,我還沒有嘗試過。 – 2015-03-31 16:22:03