my xml looks something like this:
<x>
<y a1= "abc" a2= "xyz" a3="2" a4="4" a5="8"/>
<y a1= "def" a2= "hij" a3="5" a4="10" a5="15"/>
</x>
The following code filters the values of my xml and prints the result to screen:
static void Main(string[] args)
{
int first;
int second;
int third;
XDocument doc = XDocument.Load(xmlFile);
IEnumerable<XElement> rows = from row in doc.Descendants("x")
where row.Attribute("a1").ToString() == "abc" & row.Attribute("a2").ToString() == "xyz"
select row;
foreach (XElement ele in rows)
{
IEnumerable<XAttribute> aList = from att in ele.DescendantsAndSelf().Attributes()
select att;
foreach (XAttribute xatr in atrList)
{
Console.WriteLine(att);
}
}
}
}
}
Instead of displaying the result to the screen I want to assign the values a3, a4 and a5 of the filtered row to the variables first, second and third. I also want to overwrite the values at a3, a4 and a5 with new values.
1 Answer