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

"Default" node definition

From: togix <togix@libero.it>
Date: Mon, 15 Sep 2008 11:06:24 +0200
Message-Id: <K78BYO$64ED7FEB21FFAF18D7D23E0B28B9FFCF@libero.it>
To: "xmlschema-dev" <xmlschema-dev@w3.org>

Hi all,
I'm currently working on a XML file and related Schema for its validation.. I need now to define a "default" node, that will contain all the elements that do not match any of the previous nodes of the same type.

Eg. I define three ranges for node "length", that will contain values from 1 to 300, and I need to define a "default" node at the end for the elements with value > 300.

Is it possible to do so using the XML Schema?

Any suggestion will be appreciated.

Tranks,
Claudio.



Example of XML file:
[code]<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <length>
    <range name="len_1">
      <minval>1</minval>
      <maxval>100</maxval>
    </range>
    <range name="len_2">
      <minval>101</minval>
      <maxval>200</maxval>
    </range>
    <range name="len_3">
      <minval>201</minval>
      <maxval>300</maxval>
    </range>
    <!--   nodo <range name="default">   -->
  </length>
</rules>[/code]


Example of XSD file:
[code]<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="qualified" attributeFormDefault="unqualified">

  <!-- ###  definition of simple elements and attributes  ### -->
  <xs:element name="minval" type="xs:positiveInteger"/>
  <xs:element name="maxval" type="xs:positiveInteger"/>
  <xs:attribute name="name" type="xs:string"/>
  <!-- ###  definition of complex elements  ### -->
  <xs:element name="rules">
    <xs:complexType>
      <xs:sequence>
        <!-- per Length -->
        <xs:element name="length">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="range" minOccurs="1" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element ref="minval"/>
                    <xs:element ref="maxval"/>
                  </xs:sequence>
                  <xs:attribute ref="name"/>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>[/code]
Received on Tuesday, 16 September 2008 04:38:17 GMT

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