Search code examples
c#.netxmldoctypexmlwriter

using C# WriteDocType() to generate Apple Property List-compliant XML


I'm trying to produce an XmlDocument which has a DocType as specified in Apple's Property List (P-List) format, which should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

The code I have at the moment looks like this:

using (XmlTextWriter filenameXMLWriter = new XmlTextWriter(ms, null))
{
        filenameXMLWriter.Formatting = Formatting.Indented;
        filenameXMLWriter.WriteStartDocument();
        filenameXMLWriter.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

        filenameXMLWriter.WriteStartElement("plist");
        filenameXMLWriter.WriteAttributeString("version", "1.0");
        ..
        ..
}

The DocType never gets written to the document (or at least it never appears in the output). I just get this:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">

I'd be grateful for any help.


Solution

  • I tried your code and changed the output Memory Stream to a file path and checked the output file after running the code and the DocType was written to it correctly.

    Can you try outputting to a file in your code to see if it's a problem with the WriteDocType line or the Memory Stream?

    Regards,

    Louis R