Search code examples
c#doctype

C# CreateDocumentType for non-PUBLIC


I want to get the following output:

<?xml version="1.0" encoding="Windows-1252"?>
<!DOCTYPE SUPRMRT SYSTEM "suprmrt.dtd">

I have the following code:

XmlDocument doc = new XmlDocument();
XmlDocumentType docType = doc.CreateDocumentType("SUPRMRT", "SYSTEM", "suprmrt.dtd", null);
doc.AppendChild(docType);
doc.Save(Console.out);

This produces:

<?xml version="1.0" encoding="Windows-1252"?>
<!DOCTYPE SUPRMRT PUBLIC "SYSTEM" "suprmrt.dtd">

So my question is can I get a result where PUBLIC is replaced by SYSTEM? Also, if I replace "SYSTEM" with null, I get a set of empty quotes. Can I stop that from happening?


Solution

  • Write it like this.

    XmlDocumentType docType = doc.CreateDocumentType("SUPRMRT", null, "suprmrt.dtd", null);
    

    Here is the MSDN Documentation

    publicId

    Type: System.String

    The public identifier of the document type or null. You can specify a public URI and also a system identifier to identify the location of the external DTD subset.