Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML Schema

From: "George Bina" <george@---------.--->
To: NULL
Date: 10/2/2006 3:35:00 AM

Hi,

Here it is a schema that implements 1 and 2:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
  <xs:element name="language">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="combinations"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="combinations">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="combination"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="combination">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="2" maxOccurs="2" ref="element"/>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="uniqueElements">
      <xs:selector xpath="element"></xs:selector>
      <xs:field xpath="."></xs:field>
    </xs:unique>
  </xs:element>
  <xs:element name="element" type="xs:NMTOKEN"/>
</xs:schema>

Point 1 is implemented with maxOccurs="unbounded" in
<xs:element maxOccurs="unbounded" ref="combination"/>
and point 2 is implemented with a unique constraint on the combination
element:
    <xs:unique name="uniqueElements">
      <xs:selector xpath="element"></xs:selector>
      <xs:field xpath="."></xs:field>
    </xs:unique>

Point 3 cannot be implemented with a unique constraint because the
XPath used in XML Schema does not allow predicates and one cannot refer
to the first element and the second element in a compound constraint,
that is in a constraint with two fields.
Possible approaches further are to embed Schematron rules to check that
constraint
...
 <xs:element name="combination">
    <xs:annotation>
      <xs:appinfo>
        <pattern xmlns="http://www.ascc.net/xml/schematron"
name="uniquePairTest">
          <rule context="combination">
            <assert
test="not(preceding::combination[element[1]=current()/element[1] and
element[2]=current()/element[2]])">
              We should not have duplicate combinations.
            </assert>
          </rule>
        </pattern>
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
...

or to use different names for the first element and for the second
element, for instance element1 and element2:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
  <xs:element name="language">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="combinations"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="combinations">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="combination"/>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="uniqueCombination">
      <xs:selector xpath="combination"></xs:selector>
      <xs:field xpath="element1"/>
      <xs:field xpath="element2"/>
    </xs:unique>
  </xs:element>
  <xs:element name="combination">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="element1"/>
        <xs:element ref="element2"/>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="uniqueElements">
      <xs:selector xpath="element1|element2"></xs:selector>
      <xs:field xpath="."></xs:field>
    </xs:unique>
  </xs:element>
  <xs:element name="element1" type="xs:NMTOKEN"/>
  <xs:element name="element2" type="xs:NMTOKEN"/>
</xs:schema>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
www.---.com


Nichino wrote:
> Hello,
> I'm trying to define my first Xml Schema and have a problem.
> The XML I'd like to define through the Schema is the following one.
> Can you help me please? I don't know how to insert the 3 final notes.
> Many thanks and my apologies for the trouble.
>
> Best,
> Nick
>
> <language>
> <combinations>
> <combination>
> <element> .... </element>
> <element> .... </element>
> </combination>
> <combination>
> <element> .... </element>
> <element> .... </element>
> </combination>
> <combination>
> <element> .... </element>
> <element> .... </element>
> </combination>
> </combinations>
>
> </language>
>
> Note
> 1. There is no limit to the number of combinations.
> 2. Two elements having the same content can't be combined.
>
> E.g.
>
> <combination>
> <element> pippo </element>
> <element> pippo </element>
> </combination>
>
> it's not valid.
>
> 3. it's not possible to insert two combinations having the same elements.
>
> E.g.
>
> <combinations>
> <combination>
> <element> pippo </element>
> <element> pluto </element>
> </combination>
> <combination>
> <element> pluto </element>
> <element> pippo </element>
> </combination>
> </combinations>
> 
> it's not valid.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent