• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to ensure some mandatory and some optional elements under complextype in xml?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I am facing problems in making a complex element, which allows both optional as well as mandatory elements.
For the xml below, say h2 is mandatory, while h1 is optional, and the order does not matter.

Case 1:
<root>
<h1/>
<h2/>
</root>

Case 2:
<root>
<h2/>
</root>

Case 3:
<root>
<h2/>
<h1/>
</root>

XSD:

<xs:element name="root">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="h1" minOccurs="0"></xs:element>
<xs:element name="h2" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>

the third case above fails in this xsd, but such case is valid.
I need an xsd that is valid for all the above mentioned cases.

 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like this or you mean something else.
 
He does not suffer fools gladly. But this tiny ad does:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic