← Prev in month
← Prev in thread
[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>
← Prev in month
← Prev in thread