C# XmlWriter Syntax To Write Multiple Namespace Tags

630 views Asked by At

I am attempting to write the following line with C#'s XmlWriter.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">

I seem to only seem have an option to write on xmlns (and then with no :suffix), when using the xmlWriter.WriteStartElement method.

Is it possible to do with XmlWriter?

1

There are 1 answers

3
Joshua On BEST ANSWER

Would this help? Adjusted to use LookupPrefix.

writer = XmlWriter.Create(sw);
writer.WriteStartElement("configuration");
writer.WriteAttributeString("xmlns", "patch", null, "http://www.sitecore.net/xmlconfig/");
writer.WriteAttributeString("xmlns", "set", null, "http://www.sitecore.net/xmlconfig/set/");
writer.WriteEndElement();
writer.Flush();
writer.Close();

outputs:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" />