Why does createProcessingInstruction in MSXML generate incomplete output?

<?xml?> is not a Processing Instruction. The <?xml?> construct is called the XML declaration and obeys different rules to a real Processing Instruction. Creating a PI with name ‘xml’ is not well-formed; names beginning with ‘xml’ are reserved.

To change the format of the prolog you need to configure an XMLWriter, setting ‘version’, ‘encoding’ or simply ‘omitXMLDeclaration’ to remove it altogether, which is perfectly fine since 1.0 and UTF-8 are the default values.


UTF-8 is the default encoding anyway. What you've specified is redundant, so the serializer likely omits it. The version field is not an optional field, though. If the file has an XML declaration at all, the declaration must include the version field.