The following code:
XmlSchema xmlSchema = new XmlSchema();
XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
xmlSchemaElement.Name = "SomeElement";
xmlSchema.Items.Add(xmlSchemaElement);
XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
xmlNamespaceManager.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
StringWriter stringWriter = new StringWriter();
xmlSchema.Write(stringWriter, xmlNamespaceManager);
String result = stringWriter.ToString();
Gives me:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SomeElement" />
</xs:schema>
I do not need a docType declaration.
Obviously, I could just delete the first line. But does anyone know of a way to stop the XmlSchema class from writing the docType declaration first?
source
share