The string type used to infer the encoding type. Ideally, it would be inferred from the type of the _output range, but unfortunately, the _output range API does not provide that functionality. If S does not match the encoding of the _output range, then the result will be invalid XML.
The _output range to write to.
import std.array : appender; { auto app = appender!string(); app.writeXMLDecl!string(); assert(app.data == `<?xml version="1.0" encoding="UTF-8"?>`); } { auto app = appender!wstring(); app.writeXMLDecl!wstring(); assert(app.data == `<?xml version="1.0" encoding="UTF-16"?>`w); } { auto app = appender!dstring(); app.writeXMLDecl!dstring(); assert(app.data == `<?xml version="1.0" encoding="UTF-32"?>`d); } // This would be invalid XML, because the output range contains UTF-8, but // writeXMLDecl is told to write that the encoding is UTF-32. { auto app = appender!string(); app.writeXMLDecl!dstring(); assert(app.data == `<?xml version="1.0" encoding="UTF-32"?>`); }
Writes the <?xml...?> declaration to the given output range. If it's going to be used in conjunction with XMLWriter, then either writeXMLDecl will need to be called before constructing the XMLWriter, or XMLWriter._output will need to be used to write to the output range before writing anything else using the XMLWriter. XMLWriter expects to be writing XML after the <?xml...?> and <!DOCTYPE...> declarations (assuming they're present at all), and it is invalid to put a <?xml...?> declaration anywhere but at the very beginning of an XML document.