Skip to content

track list and union ID and IDREF values in IdentityConstraint - #172

Open
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:id-table-list-union
Open

aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:id-table-list-union

Conversation

@aizu-m

@aizu-m aizu-m commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Differential run of XmlObject.validate() against the JDK Xerces validator, same schema and instances:

<xs:simpleType name='idList'><xs:list itemType='xs:ID'/></xs:simpleType>
<xs:simpleType name='idUnion'><xs:union memberTypes='xs:int xs:ID'/></xs:simpleType>

<t:ids>a b</t:ids><t:id>a</t:id>       xmlbeans: valid    xerces: cvc-id.2 multiple occurrences of ID value 'a'
<t:idu>a</t:idu><t:idu>a</t:idu>       xmlbeans: valid    xerces: cvc-id.2 multiple occurrences of ID value 'a'
<t:refs>a zz</t:refs><t:id>a</t:id>    xmlbeans: valid    xerces: cvc-id.1 no ID/IDREF binding for IDREF 'zz'
<t:refu>zz</t:refu>                    xmlbeans: valid    xerces: cvc-id.1 no ID/IDREF binding for IDREF 'zz'

Found while probing the ID/IDREF table with ID and IDREF values reached through list and union types. 16 disagreements, all in the accept direction. ValidatingXMLStreamReader gives the same results, it shares the engine.

IdentityConstraint.IdState.handleValue and IdRefState.handleValue only enter a value when its type is assignable to xs:ID, xs:IDREF or xs:IDREFS. A list whose items are IDs, a union with an ID member, or a list of such unions is not. The value never reaches the table, so duplicate IDs and dangling references validate clean. XML Schema 1.1 Part 1 3.17.5.2 puts every type derived or constructed from ID, IDREF or IDREFS in the table, and Xerces does the same.

The same code recorded an IDREF in a complex type with simple content under the complex type. That never compares equal to an ID, so <t:id>a</t:id><t:refc>a</t:refc> was rejected with "ID not found". Entries are now built from xs:ID or xs:IDREF, so that document validates.

The lookup walks the list items and the union member that accepted the value with SimpleValue.instanceType() and xgetListValue(), and skips values that are not NCNames (lexically invalid, or belonging to another union member). Directly typed ID, IDREF and IDREFS values behave as before. No disagreement remains after the change, and ./gradlew test is green. Regression test added.

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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.

2 participants