I tried to get the attributes from XNode I use the following code
XDocument document = XDocument.Load(FilePath);
var Elements = from p in document.Descendants(modality) select p.Elements("Key_Part");
//var Attriputess = from p in document.Descendants(modality) select p.Attributes();
foreach (var Element in Elements)
{
foreach (var node in Element.Nodes())
{
XmlReader reader = node.CreateReader();
string a = reader.GetAttribute("Type");
}
}
a always equal null
the XML type like this
<ShortcutList Version="8">
<Doctor>
<Key_Part >
<Key1 Name = "XX" Type= "XXXXXXXXX" > rrrr</Key1>
<Key2 Name = "XasfsaX" Type= "XXXXsafasfXXXXX" > rrsfsfrr</Key1>
</Key_Part>
I want to get Key1 , Key2 attributes and value
I must say I’ve fixed XML you’ve provided before got working query below. So you’ve not closed two last tags and you’ve closed
Key2by</Key1>tag what is wrong XML.Try out following, this will return list of entries (one per key) where each entry of anonymous type with properties: Name, Value, Type
EDIT: Fixed XML