|Problem Including schemas [message #583848]
||Mon, 08 March 2004 12:34
| Hayden Marchant
Registered: July 2009
A question that I had over a year ago has come up again and I rummaged
through my correspondence with the Eclipse XSD newsgroups/forums and found
the email below. It's a question concerning nested schemae. I have
included the email at the bottom of this mail.
I took a look at the XML Schema spec and I think that the relevant part is
at http://www.w3.org/TR/xmlschema-1/#compound-schema I took a look at the
"Professional XML Schemas" published by Wrox, and on page 274 in Chapter
8, there is a bolded out sentence that says "If the schema we include
borrows from other schemas, we only have to reference the topmost schema
for it to pull in other schemas it references".
From 26 Jan 2003:
Sorry for the long delay answering forum questions...
In the example below, B.xsd must have an include of C.xsd in order to be
valid. Including B.xsd in A.xsd will not help to resolve the ref to "id"
B.xsd. According to the spec (in my reading of it), for a QName to resolve,
there must be an explicit import/include/redefine directly in the .xsd
the "id" element simply isn't visible in B.xsd when the schema for B.xsd is
being (transitively) processed. Perhaps other processors are more tolerant
this error, perhaps even resolving the identifier via indirect
includes/imports, but XSD is strict in this regard. And since the ref to
doesn't resolve, a placeholder element is provided by XSD instead and that
placeholder doesn't have a type.
Adding the include to B.xsd is not a hack, it's required.
Hayden Marchant wrote:
> I have encountered a problem with the references schema resolving - below
> I explain the scenario:
> I have 3 xsds - A.xsd, B.xsd, and C.xsd.
> Here are snippets of my schemas:
> <xs:include schemaLocation="B.xsd"/>
> <xs:include schemaLocation="C.xsd"/>
> <xs:element name="car">
> <xs:element ref="service"/>
> <xs:element ref="model"/>
> <xs:element name="service>
> <element ref="id"/>
> <xs:element name="id>....
> <xs:element name="model...
> Now, when validating A.xsd, then the whole group of schemas is valid, even
> though the element reference 'id' that is referenced in B, is defined in
> C, and there in no include/import of C. this works since in A.xsd we are
> including both B and C, so as a whole, we have no problems.
> However, when I parse A.xsd with eclipse xsd, and I look at the
> XSDElementDeclaration for 'id' in schema B, when I call
> XSDElementDeclaration.getTypeDefinition() it returns null, and not the
> XSDTypeDefintion for id (whether it be a complex type of simple type).
> At the moment I have hacked my B.xsd to have the include statement.
> Other parsers can cope with this problem, and XML Spy lets my open my
> A.xsd is does not complain (but does complain when I open B.xsd)
> I hope that my explanation is clear.
Powered by FUDForum
. Page generated in 0.01783 seconds