Reputation: 3
i want get value of attribute base on matched value. Here my XML file
<Setup>
<Include Type="Product">
<Value uomid="8078">468922</Value>
<Value uomid="8078">468908</Value>
</Include>
</Setup>
So, i would like to take uomid base in matched value. And the process in codebehind Ex: I set my parameter value is: 468922 so my result i wanna get is 8078 of 468922 not 8087 of 468908. Thanks
Upvotes: 0
Views: 55
Reputation: 1279
Try the below Code:
SearchValue is the value which you wanna search. In your case its "468922"
public string ReturnAttribute(string SearchValue)
{
XDocument xdoc = XDocument.Load(@"C:\Tmp\test.xml");
string ReturnValue = String.Empty;
foreach (var item in xdoc.Descendants("Value"))
{
if (item.Value == SearchValue)
{
ReturnValue=item.FirstAttribute.Value;
}
}
return ReturnValue;
}
Upvotes: 1