In LINQ for XML, this is very simple:
XNamespace ns = "sphinx"; XElement element = new XElement(ns + "docset");
Or, so that the "alias" works correctly so that it looks like your examples, something like this:
XNamespace ns = "http://url/for/sphinx"; XElement element = new XElement("container", new XAttribute(XNamespace.Xmlns + "sphinx", ns), new XElement(ns + "docset", new XElement(ns + "schema"), new XElement(ns + "field", new XAttribute("name", "subject")), new XElement(ns + "field", new XAttribute("name", "content")), new XElement(ns + "attr", new XAttribute("name", "published"), new XAttribute("type", "timestamp"))));
It produces:
<container xmlns:sphinx="http://url/for/sphinx"> <sphinx:docset> <sphinx:schema /> <sphinx:field name="subject" /> <sphinx:field name="content" /> <sphinx:attr name="published" type="timestamp" /> </sphinx:docset> </container>
Jon Skeet Feb 13 '11 at 18:31 2011-02-13 18:31
source share