
Untitled
By: a guest on
Apr 26th, 2012 | syntax:
None | size: 0.64 KB | hits: 11 | expires: Never
Changing the Format of XML
<Root>
<Username>
<string>Fred</string>
<string>John</string>
</Username>
</Root>
<Root>
<Username>Fred</Username>
<Username>John</Username>
</Root>
using System.Linq;
using System.Xml.Linq;
var indoc = XDocument.Load("c:\test.xml");
var outdoc = new XDocument(
new XElement("Root",
indoc.Descendants("Root")
.Descendants("Username")
.Elements()
.Select(n => n.Value)
.Select(i => new XElement("Username", i))));
// TODO: Save doc using doc.WriteTo(xmlWriter) to the file