W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2006

Re: Ignore Order while validating XSD

From: George Cristian Bina <george@oxygenxml.com>
Date: Mon, 20 Feb 2006 11:11:34 +0200
Message-ID: <43F987C6.4080205@oxygenxml.com>
To: Ramkumar Menon <ramkumar.menon@gmail.com>
Cc: xmlschema-dev@w3.org

Hi Ram,

You can relax the content model to a choice with maxOccurs-"unbounded" 
of your possible elements and then embed a couple of Schematron rules to 
check that the number of occurrences for each element. For instance if 
you want an element test to contain a,b,c and one or more x elements in 
any order then the schema looks like below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   <xs:element name="test">
         <sch:pattern name="Check the number of occurences.">
           <sch:rule context="test">
             <sch:assert test="count(a)=1">Element a should appear 
             <sch:assert test="count(b)=1">Element b should appear 
             <sch:assert test="count(c)=1">Element c should appear 
             <sch:assert test="count(x)>=1">Element a should appear al 
least once.</sch:assert>
       <xs:choice maxOccurs="unbounded">
         <xs:element name="a"/>
         <xs:element name="b"/>
         <xs:element name="c"/>
         <xs:element name="x"/>

This scales well with the number of elements.

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

Ramkumar Menon wrote:
> Hi,
> is it possible to ignore the document order while using schema validator 
> to validate an XSD ?
> If not, is there an alternative to the following issue ?
> I have an element that has a set of elements witihn it, one of them 
> being maxOccurs="unbounded". Since I wanted to use the "xsd:all" group 
> so that I can assume unordered child nodes, the node with 
> maxOccurs="unbounded" prevents me from making such a definition.
> Any help will be appreciated.
> pls reply direcly to my email id, since I am not on this mailing list.
> rgds,
> Ram
> -- 
> Shift to the left, shift to the right!
> Pop up, push down, byte, byte, byte!
> -Ramkumar Menon
> A typical Macroprocessor
Received on Monday, 20 February 2006 09:09:40 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:32 UTC