Validation with multiple schemas

I am trying to get a parser to validate an XML file that uses a schema which includes another schema definition.  All I want to do is define an attribute in one schema/namespace and reference it as a required attribute in another schema.  I've simplified the example to 3 files: t.xsd includes s.xsd, and t.xml is my instance doc.

t.xsd (define element foo that requires s:type attribute):
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="t" xmlns:s="s" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified">
	<xsd:import namespace="s" schemaLocation="s.xsd"/>
	<xsd:element name="foo">
		<xsd:complexType>
			<xsd:attribute ref="s:type" use="required"/>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>

s.xsd:
<?xml version="1.0"?>
<xsd:schema targetNamespace="s" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsd:attribute name="type" type="xsd:string"/>
</xsd:schema>

t.xml:
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns="t" xsi:schemaLocation="t t.xsd s s.xsd" xmlns:s="s" s:type="bar"/>

If you read this far, thanks a lot.

XML Spy 4.4 says it is valid and Xerces 2.0.2 doesn't complain:

java -cp c:\xerces\xerces-2_0_2\xercesImpl.jar;c:\xerces\xerces-2_0_2\xercesSamples.jar;c:\xerces\xerces-2_0_2\xmlParserAPIs.jar sax.Counter -dv -s -v t.xml
t.xml: 541 ms (1 elems, 1 attrs, 0 spaces, 0 chars)

(Note: I had to use -dv and -s along with -v or I would get errors)

If I remove s:type="bar" from t.xml, though, XML Spy correctly says it is invalid while Xerces is still silent.

If you think this is really just a Xerces bug, I will ask somewhere else, but I'm more worried that I'm doing something fundamentally wrong.

If there is another parser/version that I could use to test my validation, I'd appreciate the tip also.

Thanks for any insights,
-- Dave

Received on Tuesday, 13 August 2002 12:03:00 UTC