Stephen Ward wrote:
Quote:
>
I have a simple little project open a xml file change a few nodes save
the file, no big deal.
>
The problem is that the doctype is getting modified when I save the file.
>
So it looks like this: <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST
1.0//EN" "_http://www.apple.com/DTDs/PropertyList-1.0.dtd_">
But when I save it : <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST
1.0//EN" "_http://www.apple.com/DTDs/PropertyList-1.0.dtd_"[]>
>
You can see at the end it appends the [] which invalidates the file.
It does not invalidate the file, actually, in the sense that it's still
legal XML. The doctype can contain internal declarations; this simply
specifies an empty declaration list. In this sense, the (abstract) doctype
is not actually modified, it's just not literally what was read in.
I agree that this is not desirable behavior, though. Ideally round-tripping
should introduce as few changes as possible.
Quote:
No where in the code do I specifically modify the doctype. Is there a
way to prevent the doctype from getting modified , this appears to be a
bug. As a workaround Ive replaced the Doctype node. But this is a kluge.
>
I've seen worse. You can do it fairly transparently with
xmlDocument.ReplaceChild(
xmlDocument.CreateDocumentType(
xmlDocument.DocumentType.Name,
xmlDocument.DocumentType.PublicId,
xmlDocument.DocumentType.SystemId,
string.IsNullOrEmpty(xmlDocument.DocumentType.Inte rnalSubset) ? null
: xmlDocument.DocumentType.InternalSubset
),
xmlDocument.DocumentType
);
The problem is that "InternalSubset" is an empty string after reading it in,
when it should be null to omit the subset declaration altogether.
--
J.