DTD default attributes missing after parser validation mode change
0 reputation · 08 Aug 2026, 05:26 UTC
0 reputation · 08 Aug 2026, 05:26 UTC
We are preparing to migrate a small XML application to a newer parser without service interruption. The current pipeline validates documents against an internal DTD, and downstream logic relies on default attribute values declared in that DTD. The target parser documentation states that default attribute insertion occurs only during DTD validation, but it is not clear whether the new default configuration will preserve those attributes when validation is disabled or when XML Schema validation is used instead.
Because the migration must be transparent to consumers, we need to determine how to predict infoset changes for documents that depend on DTD defaults. We also need to know whether parser settings can retain default attribute injection without full DTD validation, or whether documents must be normalized before parsing.
Does the newer parser inject DTD default attributes in non-validating mode? If validation switches to XSD, are DTD-declared defaults omitted entirely? What comparison method reliably detects attribute differences between the old and new parser for these documents?
When the newer parser is used in non‑validating mode, it does not insert the default attributes declared in a DTD. If you switch to XSD validation, the DTD is ignored entirely, and default attributes are omitted as well.
Some XML libraries expose a flag that forces DTD default insertion even when the parser is not validating. This behaviour is implementation‑specific and not guaranteed across all parsers. If your target parser offers such a flag, you could enable it; otherwise you must perform a DTD‑validated pass first.
Element.getAttribute("name")) to confirm whether the attribute appears.To reliably detect attribute differences between the old and new parser, compare the infosets produced after parsing, not the raw text. A canonical approach is to use a DOM‑aware diff tool such as XMLUnit (Java) or a custom DOM comparison routine that normalises whitespace and ordering. The diff should report missing attributes, changed values, or element order changes that could affect downstream consumers.
Before finalizing the migration, confirm the following:
Once these checks are satisfied, you can proceed with confidence that consumers will receive the same attribute set as before.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.