W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2004

Problem designing complexType accepting a specified element and a llowing any others

From: Hess Yvan <yvan.hess@imtf.ch>
Date: Thu, 11 Mar 2004 20:44:56 +0100
Message-ID: <DF7EC83D7AFBD411965B0008C7596EC5E0D49D@imtfexchange.imtf.ch>
To: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>

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>
</metadata>

I implemented the following xml schema 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
(I violated 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>
Received on Thursday, 11 March 2004 14:50:58 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 23:40:23 UTC