OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Problem designing complexType accepting a specified elemen

[ Lists Home | Date Index | Thread Index ]

Phil,

Thanks for your answer. The solution you proposed is to introduce a
sub-element OptionalElements that contains all others optional elements. The
XML document for which I have to write the schema have all the elements
under the section metadata as illustrated in my sample and I can not change
this requierement. 

In general manner, I would like to define a king of bag element ("metadata")
where the order of the elements is not important, that contains predefined
elements that must occurs with a given occurrences (min and max) and that
also accepts any king of others elements (same or others namespaces). I
don't know if a reach a limitation of the W3C recommendation, but from my
point of view this use case is a real concrete use case that should be
supported by W3C XML schema recommendation.

More idea?

Yvan


-----Original Message-----
From: Phil Fuhlman [mailto:pfuhlman@Dexma.com]
Sent: jeudi, 11. mars 2004 23:50
To: Hess Yvan
Subject: RE: [xml-dev] Problem designing complexType accepting a
specified element and allowing any others.


Dunno if this hits the mark, but try these (there are a lot of ways to write
/ architect a W3C XML Schema document - i tend to use a C++ / object
oriented metaphor). The ZIP contains two schema files, three test data files
(two validate with no errors while one fails) and a VBScript (sorry) that
exercises the schemas and data files with MSXML4.

Good luck ! ;-)

Phil Fuhlman
http://www.dexma.com

------------------------------------------------------------ 'metadata.xsd'
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>

<xsd:simpleType name="MetaDataClass.IdentifierType">
    <xsd:restriction base="xsd:integer" />
</xsd:simpleType>

<xsd:simpleType name="MetaDataClass.SubjectType">
    <xsd:restriction base="xsd:string" />
</xsd:simpleType>

<xsd:simpleType name="MetaDataClass.TitleType">
    <xsd:restriction base="xsd:string" />
</xsd:simpleType>

<xsd:complexType name="MetaDataClass">
    <xsd:all>
        <xsd:element name="identifier" type="MetaDataClass.IdentifierType"
minOccurs="1" maxOccurs="1" />
        <xsd:element name="subject" type="MetaDataClass.SubjectType"
minOccurs="0" maxOccurs="1" />
        <xsd:element name="title" type="MetaDataClass.TitleType"
minOccurs="0" maxOccurs="1" />
    </xsd:all>
</xsd:complexType>

<xsd:element name='metadata' type='MetaDataClass'/>

</xsd:schema>
------------------------------------------------------------ 'metadata2.xsd'
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>

<xsd:simpleType name="MetaDataClass.IdentifierType">
    <xsd:restriction base="xsd:integer" />
</xsd:simpleType>

<xsd:simpleType name="MetaDataClass.SubjectType">
    <xsd:restriction base="xsd:string" />
</xsd:simpleType>

<xsd:simpleType name="MetaDataClass.TitleType">
    <xsd:restriction base="xsd:string" />
</xsd:simpleType>

<xsd:complexType name='MetaDataClass.OptionalElementsType'>
    <xsd:sequence>
        <xsd:any minOccurs='0' maxOccurs='unbounded' processContents='lax'>
            <!-- Any kind of <element_name>element_value</element_name>
expression is permitted here. -->
        </xsd:any>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="MetaDataClass">
    <xsd:all>
        <xsd:element name="identifier" type="MetaDataClass.IdentifierType"
minOccurs="1" maxOccurs="1" />
        <xsd:element name="subject" type="MetaDataClass.SubjectType"
minOccurs="0" maxOccurs="1" />
        <xsd:element name="title" type="MetaDataClass.TitleType"
minOccurs="0" maxOccurs="1" />
	<xsd:element name="OptionalElements"
type="MetaDataClass.OptionalElementsType" minOccurs="0" maxOccurs="1"/>
    </xsd:all>
</xsd:complexType>

<xsd:element name='metadata' type='MetaDataClass'/>

</xsd:schema>

-----Original Message-----
From: Hess Yvan [mailto:yvan.hess@imtf.ch]
Sent: Thursday, March 11, 2004 1:50 PM
To: 'xml-dev@lists.xml.org'
Subject: [xml-dev] Problem designing complexType accepting a specified
element and allowing any others.


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>





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS