I am trying to convert an XML document from one format to another, and in doing so, I found that I need to insert several xmlns declarations into the root element.
Example:
<? xml version = "1.0" encoding = "utf-8"? > <Template xmlns = "http://tempuri.org/TemplateBase.xsd" XMLNS: TYPES = "http://tempuri.org/TemplateTypes.xsd">
some content
<& pattern GT;
The reason for all this is that I split the XSD schema into several XSDs to reuse generic types in this case.
Well, now I want to write this xml with XmlTextWriter, but I can not write the xmlns attribute for TYPES.
I have tried so far:
XmlWriter xmlWriter = XmlWriter.Create(filename, settings); xmlWriter.WriteStartElement("Template", "http://tempuri.org/TemplateBase.xsd"); xmlWriter.WriteAttributeString("xmlns", "TYPES", "http://tempuri.org/TemplateTypes.xsd", XmlSchema.InstanceNamespace);
When I run this code, I get the following exception:
System.ArgumentException: the prefix "xmlns" is reserved for using XML ..
Does anyone have a cure for my current headache?
user300112
source share