Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - XSD Question - Forcing attribute value in element [Thread Next] Re: XSD Question - Forcing attribute value in elementTo: NULL Date: 7/2/2005 11:52:00 PM Generally constraining valid values of one element based on the presence or
absense of another is not something that XSD can describe. Typically
described as co-constraints this is something you will have to enforce by
code or by some other layer or system.
But in this case you could change your schema so that the XML looks like
this:
<PrimaryApplicant/>
<CoApplicant/>
or
<PrimaryApplicant/>
And not
<PrimaryApplicant/>
<PrimaryApplicant/>
and not
<CoApplicant/>
And this is something XSD can define, since it is a simple sequence as
follows:
<xs:complexType name="Applicant">
</xs:complexType>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="PrimaryApplicant" type="Applicant" />
<xs:element name="CoApplicant" type="Applicant" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
"Nathan Alden" <visualcsharpcoder@h...> wrote in message
news:ejbLraYfFHA.3912@t......
> Using XSD, how can I force an element appearing in an XML document to
> contain an attribute with a specific value?
>
> Here is the complexType I've defined:
>
> <xs:complexType name="Applicant">
> <xs:attribute name="type">
> <xs:simpleType>
> <xs:restriction base="xs:string">
> <xs:enumeration value="PrimaryApplicant"/>
> <xs:enumeration value="CoApplicant"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:attribute>
> </xs:complexType>
>
> I want to require the XML to only allow this:
>
> <Applicant type="PrimaryApplicant"/>
> <Applicant type="CoApplicant"/>
>
> or this:
>
> <Applicant type="PrimaryApplicant"/>
>
> but not this:
>
> <Applicant type="PrimaryApplicant"/>
> <Applicant type="PrimaryApplicant"/>
>
> and not this:
>
> <Applicant type="CoApplicant"/>
>
> Is this possible with XML Schema?
>
> Thanks,
>
> Nate
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
