M
MENTAT
Hi Guys,
Newbie question here. Part of my xml looks like this.
<node>
<description/>
<config/>
<log/>
<transition/>
<node>
The transition element inside the node is compulsory. The other
elements are optional and can occur as many times (minOccurs="0"
maxOccurs="unbounded").
How do I write an xsd that validates this?
I tried using the choice tag with no success
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="description"/>
<xs:element ref="config" />
<xs:element ref="log" />
</xs:choice>
<xs:element ref="transition" minOccurs="1"/>
This apparently is not valid xsd. I can't wrap the transition in
another choice or sequence or all.
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="description"/>
<xs:element ref="config" />
<xs:element ref="log" />
<xs:element ref="transition" minOccurs="1"/>
</xs:choice>
This seems to be a valid xsd but doesn't actually validate the xml
properly. That is, even if the transition element is missing in the
xml, the xsd says its valid.
Tried using the <all> tag as well
<xs:all>
<xs:element ref="description" minOccurs="0" />
<xs:element ref="log" minOccurs="0" />
<xs:element ref="config" minOccurs="0" />
<xs:element ref="transition" minOccurs="1"/>
</xs:all>
The problem with this is that I can only define the non transition
elements only once. I cannot put the maxOccurs="unbounded" because it
invalidates the xsd.
I tried all the various combinations of all the above (putting
maxoccurs in the all tag etc etc.)... No go!
It seems to me that there should be an easy solution to this, some
combination that works.
Any help would be much appreciated
Newbie question here. Part of my xml looks like this.
<node>
<description/>
<config/>
<log/>
<transition/>
<node>
The transition element inside the node is compulsory. The other
elements are optional and can occur as many times (minOccurs="0"
maxOccurs="unbounded").
How do I write an xsd that validates this?
I tried using the choice tag with no success
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="description"/>
<xs:element ref="config" />
<xs:element ref="log" />
</xs:choice>
<xs:element ref="transition" minOccurs="1"/>
This apparently is not valid xsd. I can't wrap the transition in
another choice or sequence or all.
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="description"/>
<xs:element ref="config" />
<xs:element ref="log" />
<xs:element ref="transition" minOccurs="1"/>
</xs:choice>
This seems to be a valid xsd but doesn't actually validate the xml
properly. That is, even if the transition element is missing in the
xml, the xsd says its valid.
Tried using the <all> tag as well
<xs:all>
<xs:element ref="description" minOccurs="0" />
<xs:element ref="log" minOccurs="0" />
<xs:element ref="config" minOccurs="0" />
<xs:element ref="transition" minOccurs="1"/>
</xs:all>
The problem with this is that I can only define the non transition
elements only once. I cannot put the maxOccurs="unbounded" because it
invalidates the xsd.
I tried all the various combinations of all the above (putting
maxoccurs in the all tag etc etc.)... No go!
It seems to me that there should be an easy solution to this, some
combination that works.
Any help would be much appreciated