OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Extensible schemas and xs:any

[ Lists Home | Date Index | Thread Index ]

Hi Murray,

The problem is that it is using the declaration for the "Stuff" element
that is in main.xsd, because that is the one that is used in the
declaration for "Things", the root element.  The global "Stuff"
declaration in Sub.xsd is ignored, because it is never referenced in any
way, so it doesn't know that you mean that it should be MyStuffType
instead of StuffType.

You have a couple options:

1. You can add xsi:type="sub:MyStuffType" as an attribute of main:Stuff
in the instance.  This signals to the processor that you want to use the
derived MyStuffType instead of StuffType.

2. You can use substitution groups.  You can declare a global element
sub:Stuff that is in the substitution group of main:Stuff, and then
assign it it the type MyStuffType.  To do this, it would look like:

---------Main.xsd (changed to make Stuff global)--------------
<xs:schema targetNamespace="http://redcone.gbst.com/Main";
     xmlns:main="http://redcone.gbst.com/Main";
     xmlns:xs="http://www.w3.org/2001/XMLSchema";
     elementFormDefault="qualified" attributeFormDefault="qualified">

     <xs:complexType name="StuffType">
	<xs:sequence>
	    <xs:any maxOccurs="unbounded"/>
	</xs:sequence>
	</xs:complexType>
	
	<xs:element name="Things">
	   <xs:complexType>
		<xs:sequence>
		    <xs:element name="Thing" type="xs:string"/>
		    <xs:element ref="main:Stuff"/>
		</xs:sequence>
	    </xs:complexType>
	</xs:element>
	
	<xs:element name="Stuff" type="main:StuffType"/>
</xs:schema>

-----------Sub.xsd (changed to put Stuff in subst
group)----------------------
<xs:schema targetNamespace="http://redcone.gbst.com/Sub";
     xmlns:main="http://redcone.gbst.com/Main";
     xmlns:sub="http://redcone.gbst.com/Sub";
     xmlns:xs="http://www.w3.org/2001/XMLSchema";
     elementFormDefault="qualified" attributeFormDefault="qualified">

     <xs:import namespace="http://redcone.gbst.com/Main";
schemaLocation="Main.xsd"/>

     <!-- This is the Document Element -->
     <xs:element name="Stuff" substitutionGroup="main:Stuff"
type="sub:MyStuffType"/>

     <xs:complexType name="MyStuffType">
	<xs:complexContent>
	    <xs:restriction base="main:StuffType">
		<xs:sequence>
		    <xs:element name="MyStuffA" type="xs:string"/>
		    <xs:element name="MyStuffB" type="xs:string"/>
		</xs:sequence>
	    </xs:restriction >
	</xs:complexContent>
     </xs:complexType>
</xs:schema>

----Instance (changed prefix of Stuff)-----------
<main:Things
	xmlns:main="http://redcone.gbst.com/Main";
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 	
	xmlns:sub="http://redcone.gbst.com/Sub";
	xsi:schemaLocation="http://redcone.gbst.com/Sub Sub.xsd 
	                    http://redcone.gbst.com/Main Main.xsd">
	<main:Thing>String</main:Thing>
	<sub:Stuff>
		<sub:MyStuffA>blah</sub:MyStuffA>
		<sub:MyStuffB>blad</sub:MyStuffB>
	</sub:Stuff>
</main:Things>


Hope that helps!

Priscilla

-----------------------------------------------------
Priscilla Walmsley             priscilla@walmsley.com
Author, Definitive XML Schema     (Prentice Hall PTR)
----------------------------------------------------- 

> -----Original Message-----
> From: Murray Spork [mailto:m.spork@qut.edu.au] 
> Sent: Thursday, May 02, 2002 4:28 AM
> To: XML DEV
> Subject: [xml-dev] Extensible schemas and xs:any
> 
> 
> Hi all,
> 
> I am having trouble making an XML schema extensible through use of 
> "xs:any".
> 
> What I want is a main schema that has an element that is allowed to
> have a sequence of any child nodes. To do this I defined a
> global type that has an xs:any content model (is that the
> right way to say this?). The document element then has a child
> element of this type. (see Main.xsd below)
> 
> Then I would like to have a 'sub' schema that xs:imports the main
> schema - and in this sub schema I over-ride the "Stuff" element
> from  the main schema and specify that the Stuff element must have
> certain elements.
> (see Sub.xsd below)
> 
> Finally - if I construct an instance document that specifies the
> location of both schemas - and includes the Stuff element with
> child elements as declared in the Sub schema - I try to validate
> this hybrid document against both schemas. (see Stuff.xml below)
> 
> I've included below the 2 schemas and a sample instance. XSV
> complaigns about the way I've done it (I've included a bit of the
> error message below). XSV says it "can't find a type for
> wildcard-matching element <qualified name of element in Sub schema>"
> 
> Is what I'm trying to do possible? If so what am I doing wrong?
> If it's not possible - can anyone suggest a way to achieve the
> same result - that is to be able to define elements of a schema
> that can take any content - but that can be restricted by other
> schemas?
> 
> Thanks
> 
> Murray
> 
> ################### Main.xsd  ########################
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema targetNamespace="http://redcone.gbst.com/Main";
>      xmlns:main="http://redcone.gbst.com/Main";
>      xmlns:xs="http://www.w3.org/2001/XMLSchema";
>      elementFormDefault="qualified" attributeFormDefault="qualified">
> 
>      <xs:complexType name="StuffType">
> 	<xs:sequence>
> 	    <xs:any maxOccurs="unbounded"/>
> 	</xs:sequence>
> 	</xs:complexType>
> 	
> 	<xs:element name="Things">
> 	   <xs:complexType>
> 		<xs:sequence>
> 		    <xs:element name="Thing" type="xs:string"/>
> 		    <xs:element name="Stuff" type="main:StuffType"/>
> 		</xs:sequence>
> 	    </xs:complexType>
> 	</xs:element>
> </xs:schema>
> 
> ################### Sub.xsd  ########################
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- edited with XML Spy v4.0.1 U (http://www.xmlspy.com) by Nick 
> Russell (QUT) -->
> <xs:schema targetNamespace="http://redcone.gbst.com/Sub";
>      xmlns:main="http://redcone.gbst.com/Main";
>      xmlns:sub="http://redcone.gbst.com/Sub";
>      xmlns:xs="http://www.w3.org/2001/XMLSchema";
>      elementFormDefault="qualified" attributeFormDefault="qualified">
> 
>      <xs:import namespace="http://redcone.gbst.com/Main";
>          schemaLocation="Main.xsd"/>
> 
>      <!-- This is the Document Element -->
>      <xs:element  name="Stuff" type="sub:MyStuffType"/>
> 
>      <xs:complexType name="MyStuffType">
> 	<xs:complexContent>
> 	    <xs:restriction base="main:StuffType">
> 		<xs:sequence>
> 		    <xs:element name="MyStuffA" type="xs:string"/>
> 		    <xs:element name="MyStuffB" type="xs:string"/>
> 		</xs:sequence>
> 	    </xs:restriction >
> 	</xs:complexContent>
>      </xs:complexType>
> </xs:schema>
> 
> ################### Stuff.xml  ########################
> <?xml version="1.0" encoding="UTF-8"?>
> <!--Sample XML file generated by XML Spy v4.3 U 
(http://www.xmlspy.com)-->
<main:Things
	xmlns:main="http://redcone.gbst.com/Main";
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 	
	xmlns:sub="http://redcone.gbst.com/Sub";
	xsi:schemaLocation=
		"http://redcone.gbst.com/Main
		Main.xsd
		http://redcone.gbst.com/Sub
		Sub.xsd">
	<main:Thing>String</main:Thing>
	<main:Stuff>
		<sub:MyStuffA>blah</sub:MyStuffA>
		<sub:MyStuffB>blad</sub:MyStuffB>
	</main:Stuff>
</main:Things>


############ fragment of XSV error msg  ##################
<invalid char='3' code='src-resolve' line='14'
resource='file:/f:/murray/sec_lending/schemas/Stuff.xml'>
can't find a type for wildcard-matching element
{http://redcone.gbst.com/Sub}:MyStuffA</invalid>




-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl>






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS