Skip to content

honour xsi:type and xsi:nil on the root in ValidatingXMLStreamReader - #152

Open
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:vxsr-root-xsi-attrs
Open

aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:vxsr-root-xsi-attrs

Conversation

@aizu-m

@aizu-m aizu-m commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Found with a differential run of XmlObject.validate(), ValidatingXMLStreamReader and the JDK Xerces validator over the same schemas and instances. Only the stream reader disagreed, and only when the root element carried an xsi attribute.

  1. validate_event creates the Validator on the first START_ELEMENT and sends two BEGIN events: one for the type it was started with (the document type from typeForGlobalElement, or the caller's content type), then one for the element. Both passed _elemEvent, whose getXsiType/getXsiNil read the current element's attributes.
  2. Validator.beginEvent therefore checked the root's xsi:type and xsi:nil against the document type. A document type is never the base of a named type and has no nillable field.
  3. The resulting error sets _eatContent at document level. Nothing else in the document is validated, and the facets of the xsi:type are never applied.
schema: <i> is xs:int, t:small restricts xs:int with maxInclusive=5, <n> is xs:int nillable
<i xsi:type='t:small'>3</i>   validate(): valid   Xerces: valid   stream reader: cvc-elt.4.3a not derived from D=i
<i xsi:type='t:small'>9</i>   validate(): cvc-maxInclusive-valid   stream reader: cvc-elt.4.3a
<n xsi:nil='true'/>           validate(): valid   Xerces: valid   stream reader: cvc-elt.3.1 not nillable

The root BEGIN now uses _simpleEvent, which carries no xsi attributes. The CHARACTERS-first path and pushBufferedAttributes already start the validator that way. After the change the differential run has no stream-reader-only disagreement left. Regression tests added to ValidatingXMLStreamReaderTests; they fail before the change and pass after. Full ./gradlew test passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant