所有,I m New to Linq to XML and have a question on how to make XML, based on the following form specified by aaker, from a List<string >
including the name of nestedDirectories. - 请提供帮助。 增 编
供应商格式:
<eccu>
<match:recursive-dirs value="store" >
<match:recursive-dirs value="images" >
<revalidate>now</revalidate>
</match:recursive-dirs>
</match:recursive-dirs>
</eccu>
我的法典就是这样。 然而,由于你能够看到它没有产生正确格式的结果:
// 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")));
结果是:
<eccu>
<recursive-dirs value="dir1" />
<recursive-dirs value="dir2" />
<recursive-dirs value="images" />
<revalidate>now</revalidate>
</eccu>