Hi I have the following Xml to deserialize:
-
Using XmlDocument
class you can just select the "Item" nodes and iterate through the attributes:
string myXml = " "
XmlDocument doc = new XmlDocument();
doc.LoadXml(myXml);
XmlNodeList itemNodes = doc.SelectNodes("RootNode/Item");
foreach(XmlNode node in itemNodes)
{
XmlAttributeCollection attributes = node.Attributes;
foreach(XmlAttribute attr in attributes)
{
// Do something...
}
}
Or, if you want an object containing only the Attributes as List of KeyValuePairs, you could use something like:
var items = from XmlNode node in itemNodes
select new
{
Attributes = (from XmlAttribute attr in node.Attributes
select new KeyValuePair(attr.Name, attr.Value)).ToList()
};