string str = "your xml string";
XDocument document = XDocument.Parse(str);
var books = document.Descendants("book");
foreach (XElement item in books)
{
var idElement = item.Element("id");
if (idElement.HasAttributes)
{
XAttribute attr = idElement.Attribute("isPrimaryKey");
string attrValue = attr.Value;
Console.WriteLine(attrValue);
}
}
Console.Read();
XML:
="1.0"="utf-8"
<books>
<book>
<id isPrimaryKey="true">3785</id>
<name>CLR via C#</name>
</book>
</books>