Project

Profile

Help

Bug #6148

closed

xsi:type and xsi:schemaLocation on same element

Added by Michael Kay 9 months ago. Updated 5 months ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2023-07-31
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
11, 12, trunk
Fix Committed on Branch:
11, 12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

If the xsi:type and xsi:schemaLocation attributes are both present on the same element, and if the xsi:type happens to be processed first, and references a type defined in the schema pointed to by xsi:schemaLocation, then a failure occurs saying the type is unknown.

Actions #1

Updated by Michael Kay 9 months ago

Putting together a test case for this, I actually managed to get a NullPointerException in XSDImport when importing a no-namespace schema from one with a namespace which was in turn loaded using xsi:schemaLocation.

This is achieved by running Validate from the command line with -xsd:test.xsd -s:test.xml -t -xsdversion:1.1 -xsiloc:on and the following three files in the current directory:

test.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.1">
    <xs:element name="foo" type="barType"/>     
    <xs:simpleType name="barType">
        <xs:restriction base="xs:integer">
            <xs:minExclusive value="5"/>
        </xs:restriction>       
    </xs:simpleType>    
</xs:schema>

test2.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tn="foo" targetNamespace="foo" elementFormDefault="qualified">
   <xs:import schemaLocation="test.xsd"/>
	<xs:complexType name="bazType">
		<xs:simpleContent>
			<xs:extension base="barType">
				<xs:attribute name="code" type="xs:integer"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>	
</xs:schema>

test.xml

<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="foo test2.xsd" code="42" xsi:type="foo:bazType" xmlns:foo="foo">23</foo>
Actions #2

Updated by Michael Kay 9 months ago

It's failing trying to output the warning message

"The schema document at " + schemaLocation +
                        " is not being read because schema components for this namespace are already available"

because namespace is null. Easily fixed.

Actions #3

Updated by Michael Kay 9 months ago

With this fixed, the test runs successfully (document is valid) if xsi:schemaLocation precedes xsi:type, and fails saying Unknown type {foo:bazType} specified in xsi:type attribute if the order of attributes is reversed. (The parser I'm using appears to deliver attributes in the order they are written).

Actions #4

Updated by Michael Kay 9 months ago

  • Status changed from New to Resolved
  • Applies to branch 11, 12, trunk added
  • Fix Committed on Branch 11, 12, trunk added
  • Platforms .NET, Java added
Actions #5

Updated by Debbie Lockett 8 months ago

  • % Done changed from 0 to 50
  • Fixed in Maintenance Release 11.6 added

Bug fix applied in the Saxon 11.6 maintenance release.

Actions #6

Updated by O'Neil Delpratt 5 months ago

  • Status changed from Resolved to Closed
  • % Done changed from 50 to 100
  • Fixed in Maintenance Release 12.4 added

Bug fix applied in the Saxon 12.4 Maintenance release

Please register to edit this issue

Also available in: Atom PDF