CnuVas CnuVas - 6 months ago 31
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


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 })