All, I'm new to Linq to XML and have a question on how to generate XML, based on the following format prescribed by a vendor, from a List<string>
containing the names of nested directories. - Please help. Thanks
Vendor format:
<eccu>
<match:recursive-dirs value="store" >
<match:recursive-dirs value="images" >
<revalidate>now</revalidate>
</match:recursive-dirs>
</match:recursive-dirs>
</eccu>
Here's my code. However as you can see it does not produce the correctly formatted results.:
// NOTE - textBox1.Text = 'http://www.someurl.com/dir1/di2/images'
var dirs = (new Uri(textBox1.Text)).Segments.Select(dir => dir.Replace("/", String.Empty)).Where( dir => !String.IsNullOrWhiteSpace(dir)).ToList();
var x = new XDocument(new XDeclaration("1.0", null, null), new XElement("eccu", from s in dirs select new XElement("recursive-dirs", new XAttribute("value", s)), new XElement("revalidate", "now")));
This produces:
<eccu>
<recursive-dirs value="dir1" />
<recursive-dirs value="dir2" />
<recursive-dirs value="images" />
<revalidate>now</revalidate>
</eccu>