XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] <xs:all> with different elements in any order

Hi Ken / George,
   Thanks for the answer.

The following Schema meets my requirement.

<xs:element name="OBJECTS">
  <xs:complexType>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="A" type="xs:string"/>
      <xs:element name="B" type="xs:string"/>
    </xs:choice>
  </xs:complexType>
</xs:element>


On 9/19/07, G. Ken Holman <gkholman@cranesoftwrights.com> wrote:
> At 2007-09-19 18:13 +0530, Mukul Gandhi wrote:
> >    I want to validate an XML instance like following with W3C XML Schema.
> >
> ><OBJECTS>
> >   <!-- A & Bs in any order and unbounded. B can be before A also. -->
> >   <A>ddjhfj</A>
> >   <B>hghgh</B>
> >   <!-- more A & Bs -->
> ></OBJECTS>
>
> Sounds like a simple alternation.
>
> >I want a Schema like (which is invalid) following.
> >
> ><xs:element name="OBJECTS">
> >    <xs:complexType>
> >        <xs:all>
> >           <xs:element name="A" type="xs:string" maxOccurs="unbounded" />
> >           <xs:element name="B" type="xs:string" maxOccurs="unbounded" />
> >        </xs:all>
> >     </xs:complexType>
> ></xs:element>
> >
> >But this is wrong, because in this Schema maxOccurs can be 0 or 1.
>
> I'm not sure what you mean by that.
>
> Do you mean by trying <xs:all> that it is a requirement to have at
> least one of each?
>
> >Could somebody please suggest a Schema for this requirement.
>
> Since you are looking for an unbounded quantity, a simple alternation
> should work if either is optional in the whole:
>
> T:\ftemp2>type mukul.xml
> <OBJECTS>
>   <!-- A & Bs in any order and unbounded. B can be before A also. -->
>   <A>ddjhfj</A>
>   <B>hghgh</B>
>   <!-- more A & Bs -->
> </OBJECTS>
>
> T:\ftemp2>type mukul.xsd
> <?xml version="1.0" encoding="US-ASCII"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
>
> <xsd:element name="OBJECTS">
>   <xsd:complexType>
>     <xsd:choice maxOccurs="unbounded">
>       <xsd:element name="A" type="xsd:string"/>
>       <xsd:element name="B" type="xsd:string"/>
>     </xsd:choice>
>   </xsd:complexType>
> </xsd:element>
>
> </xsd:schema>
>
> T:\ftemp2>w3cschema mukul.xsd mukul.xml
> Xerces...
> No validation errors.
> Altova...
> The XML data is valid
>
> T:\ftemp2>
>
>
> If, however, you have a requirement that at least one of each are
> required and can be in any order, then things get a bit more complex:
>
>    ( A+, B, (A | B)* ) | ( B+, A, (B | A)* )
>
> T:\ftemp2>type mukul.xml
> <OBJECTS>
>   <!-- A & Bs in any order and unbounded. B can be before A also. -->
>   <B>hghgh</B>
>   <A>ddjhfj</A>
>   <B>hghgh</B>
>   <A>ddjhfj</A>
>   <A>ddjhfj</A>
>   <B>hghgh</B>
>   <B>hghgh</B>
>   <!-- more A & Bs -->
> </OBJECTS>
>
> T:\ftemp2>type mukul.xsd
> <?xml version="1.0" encoding="US-ASCII"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
>
> <xsd:element name="OBJECTS">
>   <xsd:complexType>
>     <xsd:choice>
>       <xsd:sequence>
>         <xsd:element ref="A" maxOccurs="unbounded"/>
>         <xsd:element ref="B"/>
>         <xsd:choice minOccurs="0" maxOccurs="unbounded">
>           <xsd:element ref="A"/>
>           <xsd:element ref="B"/>
>         </xsd:choice>
>       </xsd:sequence>
>       <xsd:sequence>
>         <xsd:element ref="B" maxOccurs="unbounded"/>
>         <xsd:element ref="A"/>
>         <xsd:choice minOccurs="0" maxOccurs="unbounded">
>           <xsd:element ref="B"/>
>           <xsd:element ref="A"/>
>         </xsd:choice>
>       </xsd:sequence>
>     </xsd:choice>
>   </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="A" type="xsd:string"/>
> <xsd:element name="B" type="xsd:string"/>
>
> </xsd:schema>
>
> T:\ftemp2>w3cschema mukul.xsd mukul.xml
> Xerces...
> No validation errors.
> Altova...
> The XML data is valid
>
> T:\ftemp2>
>
> The interleave concept in RELAX-NG would be really helpful here:
>
>   ( A+ & B+ )
>
> I hope this helps.
>
> . . . . . . . . . . .Ken
>
> --
> Upcoming public training: UBL and code lists Oct 1/5; Madrid Spain
> World-wide corporate, govt. & user group XML, XSL and UBL training
> RSS feeds:     publicly-available developer resources and training
> G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
> Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
> Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
> Male Cancer Awareness Jul'07  http://www.CraneSoftwrights.com/x/bc
> Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


-- 
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


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

Copyright 1993-2007 XML.org. This site is hosted by OASIS