A
dictionary
of values can be created using
XElement
and
LINQ
, where the name of the element is the key and the value of element is the value corresponding to the key as shown below:
string xmlData = @"<Erro total=""0"" razao=""PEIN"" inicio=""0"" fim=""0"">
<Criterio>
<inDistrito/>
<inConcelho/>
<inLocal/>
<inRua/>
<inPorta/>
<inCodPos/>
<inCliente/>
<inIdLocal/>
<inIdRua/>
<inEp/>
<inApartado/>
<inIdEp/>
<inPag>1</inPag>
<inMaxPag>20</inMaxPag>
<Id_Pesq>68083086</Id_Pesq>
</Criterio>
</Erro>";
XElement element = XElement.Parse(xmlData);
Dictionary<string,object> values = new Dictionary<string,object>();
element.Element("Criterio").Elements()
.Select (e => {
values.Add(e.Name.ToString(),e.Value);
return e;
}).Count ();
XElement element = XElement.Parse(xmlData);
List<KeyValuePair<string,object>> values = element.Element("Criterio").Elements()
.Select (e => new KeyValuePair<string,object>(
e.Name.ToString(),e.Value)
).ToList();