CnuVas CnuVas - 1 year ago 111
C# Question

Convert following String XML into List<string[]>

I have following string XML

<c />
<d />
<z />

Above XML String Convert to

have node & value

Output list Should like this

enter image description here

Answer Source

You can easily extract the list of all child elements using XDocument.Descendants() and use those to create string arrays, containing the element name and value. Wrap it in a list and you're done:

var result = XDocument.Parse(xml)
                      .Select(e => new [] { e.Name.LocalName, e.Value })
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download