Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Forcing a parent tag to have at least one child via an XML schema [Thread Next] Re: Forcing a parent tag to have at least one child via an XML schemaTo: NULL Date: 10/3/2008 5:53:00 AM On Oct 3, 5:37=A0pm, "Susan Harris" <susanbharris1...@yahoo.com> wrote:
> I have a document that includes info similar to:
>
> <cat>
> =A0 <name>Tiddles</name>
> =A0 <color>Purple</color>
> =A0 <age>12</age>
> =A0 <ageInCatYears>84</ageInCatYears>
> </cat>
>
> ALL elements (including <cat>) are optional. However, <cat> should not ex=
ist
> unless at least one of it children does.
>
> How can I specific via an XML schema that <cat> should not exist unless i=
t
> has at least one child?
I haven't check the Schema spec deeply, but I feel this might not be
possible with XSD 1.0. But it should be possible with the upcoming XSD
1.1 schema language (using the assertions feature).
With XSD 1.1, this should likely work:
<xs:element name=3D"cat">
<xs:complexType>
<xs:sequence>
<xs:element name=3D"name" type=3D"xs:string" minOccurs=3D"0"
maxOccurs=3D"1" />
<xs:element name=3D"color" type=3D"xs:string" minOccurs=3D"0"
maxOccurs=3D"1" />
<xs:element name=3D"age" type=3D"xs:integer" minOccurs=3D"0"
maxOccurs=3D"1" />
<xs:element name=3D"ageInCatYears" type=3D"xs:string"
minOccurs=3D"0" maxOccurs=3D"1" />
</xs:sequence>
<xs:assert test=3D"count(*) > 0" />
</xs:complexType>
</xs:element>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
