Re: abstract elements and late binding namespaces

Hi Naomi,

>I *think* this is sound design, but I can't get it to validate. 
>
Yes, the design look good and is perfectly valid. There is just one 
small error in your concrete schema. See below.

>XMLSpy chokes on validation, saying that there are undefined values for the abstract types.  I can get XML spy to validate the schemas if I *import* rather than *include* the abstract schema in the concrete schema.  But then the instance doc won't validate because the root "records" element isn't declared anywhere.
>
>XSV chokes on validation, claiming that it's expecting "[]" as content in the records element, and then tells me the header element is undeclared.  Similar tweaking with import and include statements doesn't make this error go away.
>
>Topologi chokes on validation, too.
>
</snip>

>Schema with concrete elements for "collection" type:
>
><?xml version="1.0" encoding="UTF-8"?>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  targetNamespace="http://the.namespace" xmlns:TNS="http://the.namespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
><!-- NOTE:  for instance validation debugging, xsv seems happiest with import rather than include of DB_Insert_abstract -->
><!-- NOTE:  for instance validation debugging, XMLSpy says the schemas are okay, but chokes on records element in instance doc without include. -->
><!--                             but XMLSpy chokes on schema WITH include -->
>	<xsd:include schemaLocation="abstract.xsd"/>
>
This is correct. It should be an include.

>	<xsd:element name="header" substitutionGroup="abstractHeader" type="TNS:collectionHeaderType"/>
>	<xsd:element name="record" substitutionGroup="abstractRecord" type="TNS:collectionRecordType"/>
>
Here is the first errors. What you have done by including a schema with 
no namespace into a schema with a namespace is something that is called 
a 'Chameleon' include (see [1] for more details). What this means is 
that you bring in all the components of the included schema to the 
namespace of the including schema. So, in the above element declaration 
you have declared that the header and record element should be in the 
substitutionGroup of abstractHeader and abstractRecord respectively. The 
problem is that abstractHeader and abstractRecord now have the namespace 
"http://the.namespace" just like your other components so you need to 
reference them using the TNS prefix. The following should do the trick:

<xsd:element name="header" substitutionGroup="TNS:abstractHeader" 
type="TNS:collectionHeaderType"/>
<xsd:element name="record" substitutionGroup="TNS:abstractRecord" 
type="TNS:collectionRecordType"/>

>	<xsd:complexType name="collectionHeaderType">
>		<xsd:complexContent>
>			<xsd:restriction base="headerType">
>				<xsd:sequence>
>					<xsd:element name="category" type="xsd:string" fixed="collection" />
>					<xsd:element name="link" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
>					<xsd:element name="namingAuthority" type="xsd:string" />
>				</xsd:sequence>
>			</xsd:restriction>
>		</xsd:complexContent>
>	</xsd:complexType>
>
Again instead of <xsd:restriction base="headerType"> this should be 
<xsd:restriction base="TNS:headerType">

>	<xsd:complexType name="collectionRecordType">
>		<xsd:complexContent>
>			<xsd:extension base="recordType">
>				<xsd:sequence>
>					<xsd:element name="responsibleEntityNA" type="xsd:string" />
>					<xsd:element name="brandIconURL" type="xsd:string" />
>					<xsd:element name="brandTitle" type="xsd:string" />
>				</xsd:sequence>			
>			</xsd:extension>
>		</xsd:complexContent>
>	</xsd:complexType>
>
<xsd:restriction base="recordType"> should be <xsd:restriction 
base="TNS:recordType">

>Instance document for collection type:
>
><?xml version="1.0" encoding="UTF-8"?>
><TNS:records xmlns:TNS="http://the.namespace" xsi:schemaLocation="http://the.namespace concrete.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
>	<TNS:header>
>		<TNS:category>collection</TNS:category>
>		<TNS:link linktype="collection" primary="true">oai:nsdl.org:nsdl.nsdl/00135</TNS:link>
>		<TNS:namingAuthority>nsdl.nsdl</TNS:namingAuthority>
>	</TNS:header>
>	<TNS:record>
>		<TNS:reharvestID>00002</TNS:reharvestID>
>		<TNS:secondaryID>cornell.nsdl.collections/00002</TNS:secondaryID>
>		<TNS:responsibleEntityNA>nsdl</TNS:responsibleEntityNA>
>		<TNS:brandIconURL>default.gif</TNS:brandIconURL>
>		<TNS:brandTitle>NSDL</TNS:brandTitle>
>	</TNS:record>
>	<TNS:record>
>		<TNS:reharvestID>00004</TNS:reharvestID>
>		<TNS:secondaryID>cornell.nsdl.collections/00004</TNS:secondaryID>
>		<TNS:responsibleEntityNA>nsdl</TNS:responsibleEntityNA>
>		<TNS:brandIconURL>default.gif</TNS:brandIconURL>
>		<TNS:brandTitle>NSDL</TNS:brandTitle>
>	</TNS:record>
></TNS:records>
>  
>
With the changes above your instance should validate fine.
Both TSV (Topologi Schematron Validator) and Xerces 2.0.1 validates fine 
but you have an error in the instance document because TNS:link can't 
have any attributes.

Cheers,
/Eddie

Received on Thursday, 13 June 2002 20:03:24 UTC