Everytime I call the method on
XmlDocument.Save(fooFilepath);
it inserts two square brackets at the end of the DOCTYPE tag e.g.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ARCXML SYSTEM "G:\ArcIMS\DTD\arcxml.dtd"[]>
Does anyone know why this might happen? I obviously don't want this to happen.
That is a normal (and optional) part of a DOCTYPE declaration.
<!DOCTYPE rootname SYSTEM url [DTD]>
Where DTD contains any internal subset declarations to your document.
The underlying reader used by XmlDocument
(which uses XmlTextReader
) does not distinguish between a document with an empty internal subset and one with no internal subset specified, so it will return InternalSubset == ""
for both cases.
Then when XmlDocument.Save()
is called, it sees an empty string for InternalSubset
and dutifully writes an empty internal subset: []
.
Unfortunately, XmlDocument.DocumentType.InternalSubset
is readonly, so you cannot set it to null. You can either do:
Use the lower level XmlTextWriter.WriteDocType()
to have more control.
Use XDocument
, where you can set XDocument.DocumentType.InternalSubset = null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With