my xml looks like this:
<root>
<x a1 = "abc">
<y a2 = "def">
<z value1 = 5 value2 = 10 value3 = 15/>
</y>
</x>
</root>
my main code:
static void Main(string[] args)
{
int value;
IEnumerable<XElement> xs = from x in xDoc.Descendants("x")
where (string)x.Attribute("a1") == "abc"
select x;
IEnumerable<XElement> ys = from y in xs.Descendants("y")
where (string)y.Attribute("a2") == "def"
select time;
IEnumerable<XElement> zs = from z in ys.Descendants("z")
where z.Attribute == value1
select z;
}
I am trying to set int value to value 1, 2 or 3 of node z depending on a certain condition. My problem occurs when i try to filter the required value in node z. could someone explain how I could assign the matching value of node z to int value.
If I understand you correctly, you want to select some element of z node:
Result of query –
IEnumerable<int>. You can applySingleofFirstif you sure that there will be one value, or you need first one.Also I don’t understand why you keep values as
"5"instead of simple5.