When Does xsd:any processContents='lax' Hide Undefined Elements Instead of Reporting Them?
26.5K reputation · 20 Feb 2024, 14:19 UTC
In XSD 1.0, the xsd:any wildcard supports schema extensibility by allowing elements not declared in the base schema. The processContents attribute controls whether those elements are validated against no schema, a fixed schema, or a lax schema. A common design goal is to permit extension elements while still catching accidental or misspelled elements that belong to a known namespace.
The unresolved decision concerns the interaction between processContents="lax" and the wildcard's namespace attribute. When a lax wildcard encounters an element for which no schema is available, validation ignores it. If the namespace attribute is misconfigured, such as using ##other when a specific target namespace was intended, the validator may silently accept elements that should have been flagged. The same document might validate successfully under lax processing but fail under strict processing.
Verification typically involves comparing validator output for a document containing an undefined element under both modes, using a standard JAXP validator. However, the correct choice for a given extensibility contract remains unclear.
Which conditions cause a lax wildcard to silently ignore an element that has no matching schema declaration? How does the namespace attribute on xsd:any alter that outcome? And when should a schema author prefer strict processing despite the loss of extensibility?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 20 Feb 2024, 22:38 UTC
To further clarify the behavior of processContents="lax", it is important to distinguish it from processContents="skip". While both can result in a document passing validation despite containing undefined elements, they operate on different logic:
- Lax: The validator actively searches for a schema declaration. If one is found, the element must be valid according to that schema, or a validation error is triggered. It only ignores the element if no declaration is available.
- Skip: The validator ignores the element and all of its children entirely, regardless of whether a schema declaration exists or if the content is malformed.
For those using JAXP or similar validators, this means lax provides a safety net: it allows for unknown extensions but still catches errors in known extensions. To verify this, test a document where an element matches a loaded schema but contains invalid data; lax will report the error, whereas skip will remain silent.