It seems that relative URLs specified in xsi:schemaLocation fields must be specified relative to the schemas in which they are imported. I suppose that there is some logic to it, but I have to call exception to it being rather obscure and inconsistent.
Follow this example: An instance needs to specify three schemas. The first imports the second and the third, and the second imports the third. The schemaLocation value that I would expect to work, which shows the directory structure relative to the xml file is:
xsi:schemaLocation='http://something.com/schema1 s1d/schema1.xsd http://something.com/schema2 s2d/d/schema2.xsd http://something.com/schema3 s3d/d/d/schema3.xsd'
However, since schema1 is importing schema2 and schema3, the schemaLocation value should be relative to the location of schema1.xsd:
xsi:schemaLocation='http://something.com/schema1 s1d/schema1.xsd http://something.com/schema2 ../s2d/d/schema2.xsd http://something.com/schema3 ../s3d/d/d/schema3.xsd'
However, since schema 1 imports schema2 before it imports schema3, and schema2 imports schema3, the specification for schema3 must be relative to schema2, not to schema3, so the schemaLocation value must be:
xsi:schemaLocation='http://something.com/schema1 s1d/schema1.xsd
http://something.com/schema2 ../s2d/d/schema2.xsd
http://something.com/schema3 ../../s3d/d/d/schema3.xsd'
I think this level of complexity in the resolution of relative URIs is too hard to specify. In order to determine values which work, users must trace through imports in schemas, and even then, any change in import order in an imported schema may change the required definition in the XML instance.
I have been unable to find language in the specification which requires this behavior, although perhaps I don't know where to look. Is what I'm seeing required by the specifications? Which specification and where? Or was this a decision of the implementation team?
Thanks, Webb
the complete sample files are below:
<!-- ================ file s1d/schema1.xsd ================= -->
<?xml version="1.0"?> <xsd:schema targetNamespace='http://something.com/schema1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:s2='http://something.com/schema2' xmlns:s3='http://something.com/schema3'> <xsd:import namespace='http://something.com/schema2'/> <xsd:import namespace='http://something.com/schema3'/> <xsd:element name="document"> <xsd:complexType> <xsd:sequence> <xsd:element ref='s2:document'/> <xsd:element ref='s3:document'/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
<!-- ================ file s2d/d/schema2.xsd ================= -->
<?xml version="1.0"?> <xsd:schema targetNamespace='http://something.com/schema2' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:s3='http://something.com/schema3'> <xsd:import namespace='http://something.com/schema3'/> <xsd:element name="document"> <xsd:complexType> <xsd:sequence> <xsd:element ref="s3:document"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
<!-- ================ file s3d/d/d/schema3.xsd ================= -->
<?xml version="1.0"?> <xsd:schema targetNamespace='http://something.com/schema3' xmlns:xsd='http://www.w3.org/2001/XMLSchema'> <xsd:element name="document"/> </xsd:schema>
<!-- ================ file instance-fails-1.xml ================= -->
<?xml version="1.0"?>
<s1:document
xmlns:s1='http://something.com/schema1'
xmlns:s2='http://something.com/schema2'
xmlns:s3='http://something.com/schema3'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://something.com/schema1 s1d/schema1.xsd
http://something.com/schema2 s2d/d/schema2.xsd
http://something.com/schema3 s3d/d/d/schema3.xsd'>
<s2:document>
<s3:document/>
</s2:document>
<s3:document/>
</s1:document><!-- ================ file instance-validates-1.xml ================= -->
<?xml version="1.0"?>
<s1:document
xmlns:s1='http://something.com/schema1'
xmlns:s2='http://something.com/schema2'
xmlns:s3='http://something.com/schema3'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://something.com/schema1 s1d/schema1.xsd
http://something.com/schema2 ../s2d/d/schema2.xsd
http://something.com/schema3 ../../s3d/d/d/schema3.xsd'>
<s2:document>
<s3:document/>
</s2:document>
<s3:document/>
</s1:document>
<!-- ================ file s1d/schema1b.xsd ================= -->
<?xml version="1.0"?> <xsd:schema targetNamespace='http://something.com/schema1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:s2='http://something.com/schema2' xmlns:s3='http://something.com/schema3'> <xsd:import namespace='http://something.com/schema3'/> <xsd:import namespace='http://something.com/schema2'/> <xsd:element name="document"> <xsd:complexType> <xsd:sequence> <xsd:element ref='s2:document'/> <xsd:element ref='s3:document'/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
<!-- ================ file instance-validates-1b.xml ================= -->
<?xml version="1.0"?>
<s1:document
xmlns:s1='http://something.com/schema1'
xmlns:s2='http://something.com/schema2'
xmlns:s3='http://something.com/schema3'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://something.com/schema1 s1d/schema1b.xsd
http://something.com/schema2 ../s2d/d/schema2.xsd
http://something.com/schema3 ../s3d/d/d/schema3.xsd'>
<s2:document>
<s3:document/>
</s2:document>
<s3:document/>
</s1:document>At 09:24 PM 6/20/2003, Michael Glavassevich wrote:
As I understand it, relative URIs are relative to the resource in which they are referenced (that's not necessarily the resource in which they're declared), so if you're referencing schema 2 from schema 1, the URI for schema 2 is relative to schema 1, not your instance document.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
