W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2003

Re: Help with this sample

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 22 Sep 2003 15:36:51 +0100
Message-ID: <92243153866.20030922153651@jenitennison.com>
To: chris@publicbar.com
Cc: xmlschema-dev@w3.org

Hi Chris,

> I am trying to validate some xml against the following, In the attached
> files i have:
>
> bl.xsd:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <xs:schema targetNamespace="http://www.blexample.com"
>            xmlns="http://www.blexample.com"
>            xmlns:xs="http://www.w3.org/2001/XMLSchema"
>            xmlns:hl7="http://www.blexample.com"
>            elementFormDefault="qualified">
> <xs:include schemaLocation="../dt/bldatatypes.xsd" />
>
> <xs:element name="TypeValidation">
>   <xs:complexType>
[snip]
>     <xs:sequence>
[snip]
>       <xs:element ref="addr"/>
>     </xs:sequence>
>   </xs:complexType>
> </xs:element>

Above, you're saying that the <addr> element within the
<TypeValidation> element is validated against the global element
declaration for the <addr> element. The global element declaration for
the <addr> element is:

> <xs:element name="addr">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element name="addr" type="AD" minOccurs="0" maxOccurs="1" />
>     </xs:sequence>
>   </xs:complexType>
> </xs:element>

This says that the <addr> element might contain another <addr> element
of type {http://www.blexample.com}AD (otherwise it must be empty).

Already, that means your instance document:

> bl.xml:
>
> <?xml version="1.0" encoding="utf-8"?>
> <TypeValidation xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
>                 xsi:schemaLocation='http://www.blexample.com bl.xsd'
>                 xmlns='http://www.blexample.com'>
[snip]
> <addr>
>     <city>test</city>  <--------------- PROBLEM
> </addr>
> </TypeValidation>

is invalid; according to your schema, the <addr> element directly
within the <TypeValidation> element must either be empty or contain
another <addr> element of type {http://www.blexample.com}AD.

Perhaps you meant the <addr> element to be of type
{http://www.blexample.com}AD? In that case, the global element
declaration should look like:

<xs:element name="addr" type="AD" />

and if you want to say that the <addr> element within the
<TypeValidation> element is optional, you need to say that when you
refer to this element declaration:

  <xs:element ref="addr" minOccurs="0" />

I haven't tried out this change, so there might be other things in
addition that are preventing it from working...
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Monday, 22 September 2003 10:37:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:39 GMT