Re: [Moderator Action] problem with validating against multiple, independent schemas

Dear Mr. Thompson,

Just thought I'd let you know that I made the change you suggested, and XSV performed very well.  It successfully fetched both the
primary and the imported schemas and validated the instance against them.  I also tried putting a couple of  mistakes in the
imported schema section of the instance: I used a string where an integer was expected, and I used an illegal tag name.  XSV
reported both errors.  It is a very useful tool.  Thanks again for your help.

Steve Monk

"Henry S. Thompson" wrote:

> Steve Monk <smonk@geocities.com> writes:
>
> > Hello.  I hope this is the appropriate forum for this message --
> > apologies if it isn't.
> >
> > I'm trying to validate an instance document that has been created using
> > two separate schemas.  Most of the examples of using multiple
> > schemas that I've encountered are cases where one schema is imported
> > into, and used to define elements in, the other.  But I want the two
> > schemas to remain independent until validation time.   The example given
> > in sections 5.5 and 5.6 of "XML Schema Part 0: Primer" seems to
> > be doing almost what I want, so it seems like it should be possible.
> >
> > Below is some markup to illustrate what I'm after.  I've tried running
> > this through two processors: Oracle XML Schema Validator 0.9 Alpha
> > and XML Spy 3.0 Beta.  The Oracle processor doesn't like the reference
> > to the second schema -- it complains that the "Data" element (in the
> > instance) is invalid (and then, of course, that all children have
> > invalid namespaces).  XML Spy has the opposite problem:  it claims that
> > everything from the second namespace is valid in the instance even when
> > I change the instance so that it DOES contain invalid elements. (For
> > example, I tried mis-spelling "Item" as "Ite" and XML Spy went happily
> > right over it.)  So, one processor refuses to accept the second
> > namespace, and the other processor accepts it but then doesn't use it.
> > (By the way, I also tried obvious alternatives such as in-lining the
> > namespace in the "Data" element, as in the Primer example mentioned
> > above, but nothing seems to work.)
> >
> > So, I'm stuck, and my questions are:  Is it in fact possible to do what
> > I'm trying to do?  If so, is my markup all right?  If so, does anyone
> > know
> > of a processor that will validate the instance properly?
> >
> > Many thanks for any feedback.
> >
> > Steve Monk
> >
> >
> >
> > INSTANCE:
> >
> > <?xml version="1.0"?>
> > <ImportedStuff xmlns="http://www.myorg.com/languageOne"
> >  xmlns:two="http://www.myorg.com/languageTwo"
> >  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
> >  xsi:schemaLocation="http://www.myorg.com/languageOne languageOne.xsd
> >     http://www.myorg.com/languageTwo languageTwo.xsd">
> >
> >  <Description>
> >   <Comment>Here is some data based on the other schema</Comment>
> >   <Author>Steve Monk</Author>
> >  </Description>
> >  <ExternalData>
> >   <two:Data>
> >    <two:Order>
> >     <two:Item>Amplifier</two:Item>
> >     <two:Quantity>2</two:Quantity>
> >    </two:Order>
> >    <two:Order>
> >     <two:Item>CD Player</two:Item>
> >     <two:Quantity>4</two:Quantity>
> >    </two:Order>
> >   </two:Data>
> >  </ExternalData>
> > </ImportedStuff>
> >
> >
> > SCHEMA ONE ("languageOne.xsd"):
> >
> > <schema targetNamespace="http://www.myorg.com/languageOne"
> >  xmlns="http://www.w3.org/1999/XMLSchema"
> >  xmlns:one="http://www.myorg.com/languageOne">
> >
> >  <element name="ImportedStuff">
> >   <complexType>
> >    <element ref="one:Description" maxOccurs="1"/>
> >    <element ref="one:ExternalData"/>
> >   </complexType>
> >  </element>
> >
> >  <element name="Description" type="one:descriptionType"/>
> >  <element name="ExternalData" type="one:externalDataType"/>
> >
> >  <complexType name="descriptionType">
> >   <element name="Comment" type="string"/>
> >   <element name="Author" type="string"/>
> >  </complexType>
> >
> >  <complexType name="externalDataType">
> >   <any namespace="##other" processContents="strict" minOccurs="1"/>
> >  </complexType>
> >
> > </schema>
> >
> >
> > SCHEMA TWO ("languageTwo.xsd"):
> >
> > <schema targetNamespace="http://www.myorg.com/languageTwo"
> >  xmlns="http://www.w3.org/1999/XMLSchema"
> >  xmlns:two="http://www.myorg.com/languageTwo">
> >
> >  <element name="Data">
> >   <complexType>
> >    <element name="Order" type="two:orderType" maxOccurs="unbounded"/>
> >   </complexType>
> >  </element>
> >
> >  <element name="Item" type="string"/>
> >  <element name="Quantity" type="integer"/>
> >
> >  <complexType name="orderType">
> >   <element ref="two:Item"/>
> >   <element ref="two:Quantity"/>
> >  </complexType>
> > </schema>
>
> Your plan is fine, your instance is fine, your schemas have a small
> bug in them, which doesn't explain the failures you report.
>
> Here's a fragment of the output from the validator you didn't try,
> namely XSV [1]:
>
> Validation error: in unnamed entity at line 9 char 3 of file:/projects/ltg/users/ht/xml/xmlschema/monk/instance.xml:
>  element {http://www.myorg.com/languageOne}:Comment not allowed here in element {http://www.myorg.com/languageOne}:Description
>   1: {None}:Comment->2
>   2: {None}:Author->3
> * 3:
>
> There were 17 errors of this sort, all arising from your (perfectly
> reasonable) use of local element declarations.  As currently spec'ed,
> elements declared locally must occur unqualified in instances.  To
> validate your document as written, with no errors and the <any ...strict/>
> operating as you intended, I added the following to the <schema>
> element of your schemas:
>
>  elementFormDefault="qualified"
>
> Try making that edit and giving the result to XSV -- you'll see you've
> got the effect you wanted.
>
> ht
>
> [1] http://cgi.w3.org/cgi-bin/xmlschema-check
> --
>   Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
>           W3C Fellow 1999--2001, part-time member of W3C Team
>      2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
>             Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
>                      URL: http://www.ltg.ed.ac.uk/~ht/

Received on Thursday, 18 May 2000 22:42:47 UTC