Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:49:24+00:00 2026-05-26T14:49:24+00:00

Say that I have a PetCage element that should contains one and only one

  • 0

Say that I have a PetCage element that should contains one and only one AnimalElement type like so:

<PetCage>
    <Cat Name="Kitty">
</PetCage>

<PetCage>
    <Dog Name="Buddy">
</PetCage>

Both Cat and Dog are of AnimanlElement type. How can I express said rule in XSD?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:49:25+00:00Added an answer on May 26, 2026 at 2:49 pm

    What you require is a choice element in your schema. It’ll allow you to express that only one from a set of elements may appear.

    EDIT: you’ll need to specify a name for the element, either directly via name or in reference to an element defined elsewhere via ref.

    Your only alternative as far as I know is to have something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    
        <xs:element name="PetCage">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="animal" type="Animal" minOccurs="1" maxOccurs="1"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
        <xs:complexType name="Animal" abstract="true">
            <xs:attribute name="Name" type="xs:string" />
        </xs:complexType>
    
        <xs:complexType name="Cat">
            <xs:complexContent>
                <xs:extension base="Animal"></xs:extension>
            </xs:complexContent>
        </xs:complexType>
    
    </xs:schema>
    

    This would validate XML files of a form like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <PetCage>
        <animal xsi:type="Cat" Name="String"/>
    </PetCage>
    

    Unfortunately this leaves you tied to that animal element name. I doubt that XML Schema allows you to specify a specific type and lets you use a wildcard for the name. XML Schema validates based on element names and, if the element is defined with an abstract type, the xsi:type attribute. There is an xs:any declaration, but that can’t be tied to any specific type. The following will validate as best as possible, but still allows any element defined under the schema root to be used:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    
        <xs:element name="PetCage">
            <xs:complexType>
                <xs:sequence>
                    <xs:any processContents="strict" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
        <xs:complexType name="Animal" abstract="true">
            <xs:attribute name="Name" type="xs:string" />
        </xs:complexType>
    
        <xs:element name="cat" />
        <xs:complexType name="Cat">
            <xs:complexContent>
                <xs:extension base="Animal"></xs:extension>
            </xs:complexContent>
        </xs:complexType>
    
    </xs:schema>
    

    It would validate this correctly:

    <?xml version="1.0" encoding="UTF-8"?>
    <PetCage>
        <cat Name="snookums"/>
    </PetCage>
    

    … but it wouldn’t stop you from putting a PetCage in a PetCage.

    I’m hoping someone with good knowledge of the XML Schema spec can confirm that this is correct or, preferably, offer the desired solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have a model like this: User(db.Model): name = db.StringProperty() interests =
Say that I have a data model called Widget . If I pick one
Say that i have a generic dictionary with data like this (I hope the
Say that I have two figures in matplotlib, with one plot per figure: import
Say that I have three button elements in one parent div. Assuming that these
Lets say that we have a local variable of value type (struct for example).
Say that I have one constructor that takes an input and another that uses
Say that I have some SELECT statement: SELECT id, name FROM people ORDER BY
Say that I have a HTML that links to two scripts: ... <script type=text/javascript
let's say that you want to select all rows from one table that have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.