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

  • SEARCH
  • Home
  • 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 8704021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:59:40+00:00 2026-06-13T02:59:40+00:00

I am trying to determine how to modify my XSD to utilize an enumeration

  • 0

I am trying to determine how to modify my XSD to utilize an enumeration in two places in XML but with different data types. I’m using Visual Studio 2010 as my XML editor.

Imagine an XML doc that contains both types of vehicles and orders for said vehicles. Rules are as follows:

  • Each vehicle must have a unique attribute – model – so attribute
    should be of type xs:ID.
  • Each order can have multiple vehicles, so
    model attribute should be of type xs:string or the like.

Here is my XML file — Test.xml

<?xml version="1.0" encoding="utf-8" ?>

<sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="Test.xsd">
  <vehicles>
    <vehicle model="Equinox" />
    <vehicle model="Impala"/>
    <!-- This should not be allowed because it's not unique -->
    <vehicle model="Impala" />
    <!-- This should not be allowed because it is not a valid model -->
    <vehicle model="Apple" />
  </vehicles>
  <orders>
    <order orderid="123">
      <item quantity="3"  model="Equinox" />
      <item quantity="2"  model="Impala" />
      <item quantity="3"  model="Impala" />
    </order>
  </orders>
</sample>

Here is my XSD file – Test.xsd (in same location as XML)

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           attributeFormDefault="unqualified"
           elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="sample">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="vehicles">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="vehicle">
                <xs:complexType>
                  <!-- this instance of model should be unique -->
                  <xs:attribute name="model" type="UniqueModel" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="orders">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="order">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="item" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:attribute name="quantity" type="xs:unsignedByte" use="required" />
                        <!-- this instance of model can be repeated -->
                        <xs:attribute name="model" type="ModelList" use="required" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="orderid" type="xs:unsignedByte" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="UniqueModel">
    <xs:restriction base="xs:ID">
      <!-- I want to import ModelList here-->
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ModelList">
    <xs:union memberTypes="ChevyModelList DodgeModelList" />
  </xs:simpleType>

  <xs:simpleType name="ChevyModelList">
    <xs:restriction base="xs:normalizedString">
      <xs:enumeration value="Equinox" />
      <xs:enumeration value="Impala" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="DodgeModelList">
    <xs:restriction base="xs:normalizedString">
      <xs:enumeration value="Charger" />
      <xs:enumeration value="Ram" />
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

I’ve done many Google and Stack Overflow searches trying to determine if this is possible but couldn’t find anything relevant.

Perhaps I need to go back to my original thoughts — which was to restrict the data using xs:unique. I can’t get this to work, either:

<xs:element name="vehicles">
  <!-- vehicle complexType here -->
  <xs:unique name="uniqueModel">
    <xs:selector xpath="vechicle" />
    <xs:field xpath="@model" />
  </xs:unique>
</xs:element>

Any help on getting either solution to work would be awesome!

Thanks!
Thad

  • 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-06-13T02:59:41+00:00Added an answer on June 13, 2026 at 2:59 am

    The xs:ID type means more than just uniqueness, it also restricts the value to be a valid XML name, which in particular means no spaces and not starting with a number (you couldn’t have, for example, a Peugeot model named “307”). I’d probably approach the problem by using a key

    <xs:element name="sample">
      <xs:key name="modelName">
        <xs:selector xpath="vehicles/vehicle" />
        <xs:field xpath="@model" />
      </xs:key>
      <xs:keyRef name="orderModel" refer="modelName">
        <xs:selector xpath="orders/order/item" />
        <xs:field xpath="@model" />
      </xs:keyRef>
    

    and make the vehicle element’s model attribute be of type ModelList. The key should ensure that the model names within vehicles are unique, and the keyRef checks that the model mentioned in each order item is in fact one of those listed under vehicles. That way you don’t actually need to restrict the type of the item/@model attribute at all, it could just be a plain xs:string as the keyRef will enforce the enumeration for you.

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

Sidebar

Related Questions

I am trying to determine if a phone is located in this polygon using
I'm trying to determine the iPhone user's location using a CLLocationManager and CLGeocoder. My
I'm trying to determine how to count the matching rows on a table using
Recently I was trying to determine the time needed to calculate a waveform using
I'm trying to determine the differences between two collections. private ObservableCollection<SomeObject> _objectList = null;
I am trying to determine the midpoint between two locations in an MKMapView .
I am trying to determine whether a ring is contained by another ring using
I'm trying to determine the best way to format two columns of text like
I'm trying to determine if my Kinect is plugged into the PC using the
I'm using Visual Studio 2008 and I'm trying to get a project that I

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.