[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problem designing complexType accepting a specified elemen


xs element optional
Do you mean that what I tried to implement is not possible with XML schema ?

I dont have experience with relaxNG, but I will investigate it in the
future. For the moment I have to use XML schema.

Any idea how to implement what I want to do ?

Yvan

-----Original Message-----
From: Mike Fitzgerald [mailto:mikefz@w...]
Sent: jeudi, 11. mars 2004 22:07
To: Hess Yvan
Cc: 'xml-dev@l...'
Subject: Re:  Problem designing complexType accepting a
specified element and a llowing any others.


Why not just use RELAX NG? [1] I don't know if this RNG schema captures all
your 
requirements, but your two instances are valid wrt it. The interleave
element is 
useful here.[2] In this content model, identifier is required but the other 
elements are optional (zero or one), but they may all be interleaved, that
is, 
they can appear in any order together.

<grammar xmlns="http://relaxng.org/ns/structure/1.0"
  ns="http://www.imtf.com/test"
  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

<start>
<element name="metadata" xmlns="http://relaxng.org/ns/structure/1.0">
  <interleave>
   <element name="identifier">
    <data type="string"/>
   </element>
   <ref name="other"/>
  </interleave>
</element>
</start>

<define name="other">
<optional>
  <element name="name">
   <data type="string"/>
  </element>
</optional>
<optional>
  <element name="subject">
   <data type="string"/>
  </element>
</optional>
<optional>
  <element name="title">
   <data type="string"/>
  </element>
</optional>
</define>

</grammar>

You can of course refine the datatypes to your liking. If you must use XML 
Schema, just translate this RNG schema into XSD with Trang.[3] I used the
Jing 
validator to validate your instances against this schema.[4]

Mike

[1] http://relaxng.org
[2] http://relaxng.org/tutorial-20011203.html#IDAN1YR
[3] http://thaiopensource.com/relaxng/trang.html
[4] http://thaiopensource.com/relaxng/jing.html


Hess Yvan wrote:

> I want to design a complexType named "metadata" that forces the presence
of
> an "identifier" element and allows any others elements not predefined.
> Moreover the "identifier" and the others elements can appear in any order
> into the "metadata" element. Here are examples of valid xml instances:
> 
> <metadata xmlns="http://www.imtf.com/test">
>   <identifier>urn:hsc:1234</identifier>
>   <name>Hess Yvan</name>
> </metadata>
> 
> <metadata xmlns="http://www.imtf.com/test">
>   <subject>This is the subject</subject>
>   <identifier>urn:hsc:1234</identifier>
>   <title>This is the title</title>
> </metadata>
> 
> I implemented the following xml schema complexType but it doesn't work: 
> 
> <xs:element name="metadata">
>   <xs:complexType>
>     <xs:choice minOccurs="0" maxOccurs="unbounded">
>       <xs:element name="identifier" type="xs:string"/>
>       <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
>     </xs:choice>
>   </xs:complexType>
> </xs:element>
> 
> 
> I get the following error with Xerces validation and a similar one with
XSV
> (it seems I violate the "Unique Particle Attribution"). 
> 
> [Error] choice.xsd:4:23: cos-nonambig:
"http://www.imtf.com/test":identifier
> and
>  WC[##any] (or elements from their substitution group) violate "Unique
> Particle
> Attribution". During validation against this schema, ambiguity would be
> created
> for those two particles.
> choice.xml: 571 ms (3 elems, 1 attrs, 0 spaces, 30 chars)
> 
> If I change my xml schema using sequence instead of choice as follow:
> 
> <xs:element name="metadata">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element name="identifier" type="xs:string"/>
>       <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
>     </xs:sequence>
>   </xs:complexType>
> </xs:element>
> 
> it works but in this case the "identifier" element must be at the FIRST
> position and I don't want that !!! 
> 
> Please can you help me to solve this problem. I have no idea how to solve
it
> !!!
> 
> Regards. Yvan Hess
> 
> --------------------------------------------------------
> XML file:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <metadata xmlns="http://www.imtf.com/test"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.imtf.com/test choice.xsd">
>    <identifier>urn:hsc:1234</identifier>
>    <name>Hess Yvan</name>
> </metadata>
> 
> --------------------------------------------------------
> XML schema file:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema targetNamespace="http://www.imtf.com/test"
> xmlns="http://www.imtf.com/test"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
>    <xs:element name="metadata">
>       <xs:complexType>
>          <xs:choice minOccurs="0" maxOccurs="unbounded">
>             <xs:element name="identifier" type="xs:string"/>
>             <xs:any processContents="lax" minOccurs="0"
> maxOccurs="unbounded"/>
>          </xs:choice>
>       </xs:complexType>
>    </xs:element>
> </xs:schema>
> 
> 
> 
> 
> -----------------------------------------------------------------
> 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://www.oasis-open.org/mlmanage/index.php>
> 

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.