aspose file tools
The moose likes XML and Related Technologies and the fly likes How to ensure some mandatory and some optional elements under complextype in xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "How to ensure some mandatory and some optional elements under complextype in xml?" Watch "How to ensure some mandatory and some optional elements under complextype in xml?" New topic
Author

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

rohit chawla
Greenhorn

Joined: Apr 05, 2011
Posts: 8
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.

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 357
    
    1
Like this or you mean something else.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to ensure some mandatory and some optional elements under complextype in xml?
 
Similar Threads
jaxb:properties
To specify one of the value within XSD enumeration tag as mandatory
Help me for xsd creation
Help in correcting a schema
Unique particle attribution rule bit me - why?