Question

How can I get the value of title1 from this string in a datatable using xDocument

<Person ActionType = "Update"  Title1="Miss" />

I tried descendants, XAttributes and all sorts...Maybe input is wrong but

XDocument xml = XDocument.Parse(row["XMLTransaction"].ToString());

IEnumerable<XAttribute> query =
from transaction in xml.Root.Elements()
select transaction.Attribute(attribute);
Was it helpful?

Solution

If that string is your literal XML then you should omit the .Elements() part.

Even shorter with XElement instead of XDocument :

 var xml = XElement.Parse(row["XMLTransaction"].ToString());

 IEnumerable<XAttribute> query = xml.Attributes();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top