XSD maxOccurs unbounded validation limits and parser memory thresholds
0 reputation · 11 Dec 2021, 06:38 UTC
Element Cardinality Constraints and Parser Resource Bounds
XML Schema (XSD) 1.0 and 1.1 permit the maxOccurs attribute to be set to unbounded, allowing an unrestricted number of element occurrences in a document instance. This flexibility creates a tension between schema expressiveness and parser resource consumption.
When a DOM parser processes a document containing a large unbounded sequence, the entire tree is materialized in memory before validation completes. The validation layer itself does not expose a standard mechanism to enforce a runtime ceiling on occurrences without altering the schema definition.
SAX parsers avoid full tree construction but still invoke validation callbacks for each element, incurring linear overhead proportional to the sequence length. The XSD specification does not mandate a specific parser implementation strategy for handling unbounded cardinality under memory pressure.
- Is there a standardized API or configuration option in common XSD validators (e.g., Xerces, Saxon) to impose a hard occurrence limit during validation without schema modification?
- How do lax versus strict validation modes differ in their handling of unknown elements within an unbounded sequence when entity expansion limits are enforced?