Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSD Question - Forcing attribute value in element

From: "Chris Lovett" <someone@------.------>
To: 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
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent