Optional element exists if has inner elements
Hi.
How do I make an optional element to not exist if it has no inner elements?
For example, I have the following snippet of XML schema:
<xs:element name="Box" type="myXml:BoxType" minOccurs="0" maxOccurs="1"/>
<xs:complexType name="BoxType">
<xs:sequence>
<xs:element name="Ball" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="Pen" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
1st XML example:
<Box>
<Ball>Blue</Blue>
<Pen>Red</Pen>
<Pen>Black</Pen>
</Box>
2nd XML example:
<Box/>
In the 2nd example, because <Box> element has no inner elements, I like <Box> element to not exist at all. How do I modify the above XML schema to do that? I like <Box> element to exist if it has at least 1 inner element, else no <Box> element at all.
|