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 8856941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:28:21+00:00 2026-06-14T14:28:21+00:00

Is it possible to specify an equivalent of HTML’s <option selected> in XSD —

  • 0

Is it possible to specify an equivalent of HTML’s <option selected> in XSD — exactly and only one element has a particular attribute?

For example, given the following example XML fragment:

<foo-list>
  <foo/>
  <foo bar="bar"/>
  <foo/>
</foo-list>

I can write the following XSD to ensure that only one foo has @bar:

<xs:element name="foo-list">
  <!-- FOO-LIST contains [1..n] FOO elements -->
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="foo" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <!-- any FOO with @BAR must have unique @BAR -->
  <xs:unique name="oneFooBar">
    <xs:selector xpath="foo"/>
    <xs:field xpath="@bar"/>
  </xs:unique>
</xs:element>
<xs:element name="foo">
  <xs:complexType>
    <!-- FOO has optional @BAR -->
    <xs:attribute name="bar">
      <xs:simpleType>
        <!-- @BAR must = "bar", if specified -->
        <xs:restriction base="xs:string">
          <xs:enumeration value="bar"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>
</xs:element>

Assuming everything’s properly qualified, and that my decision to use a solitaire enumeration instead of a pattern is sound:

1) does this schema sensibly mean what I intended? (i.e. there are zero or one <foo bar="bar"/> and zero or more <foo/> in the <foo-list>)

2) is there a way to require that there be exactly one <foo bar="bar"/> ?

  • 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-14T14:28:22+00:00Added an answer on June 14, 2026 at 2:28 pm

    1) Yes, it does, in a “weird” workaround-ish way.

    2) Not with stock XSD 1.0. Throw in Schematron, and you’re all set. Or move to XSD 1.1 with assertions (which allows you exactly what Schematron does for what you want). The thing is, since you’re not specifying a target platform, XSD 1.1 implementations are hard to come by (Java has a free option in Xerces and paid in Saxon EE) but others, such as .NET have nothing free. A Schematron “compiler” is really just a tranformation of the schema into XSLT; it can be 1.0 or 2.0, which means it can be used to augment a normal XSD 1.0 on virtually any (reasonable) platform.

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

Sidebar

Related Questions

Is it possible to specify fields while doing a FindAndModify, so only one field
Possible Duplicate: How do I specify the equivalent of volatile in VB.net? What is
is it possible to specify that a NSMutableArray can only contain a certain type
Is it possible to specify a position in terms of Scaled coordinates in one
Is it possible to specify the equivalent of a default document for directories in
Is it possible to specify the equivalent of a default document for directories in
Is it possible to specify your own thumbnail for a video that has been
Is it possible to specify validation rules for a particular entry in a Settings.bundle?
Is it possible to specify include paths for C and C++ in a pkg-config
Is it possible to specify the target platform (x64, x86) when building a project?

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.