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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:30:45+00:00 2026-06-08T17:30:45+00:00

Is it possible to define a type which can be either a keyref or

  • 0

Is it possible to define a type which can be either a keyref or a number literal? Just like in any typed programming language you can assign either a number literal OR the name of another variable to a numeric variable. I’m making a schema to define drawing api elements (for another programming language) and would like to define a color type that can either be a hexadecimal literal (such as 0xFF0000 for bright red) OR be a reference to a color defined elsewhere. So you could do (in a XML document):

<color key="dialogBorder1">0x222222</color>
<color key="dialogFill1">0xCCCCCC</color>

<!-- later... -->
<windowTheme name="warningWindow">
  <border>
    <color>0xFF0000</color> <!-- defined literally -->
  </border>
  <fill>
    <solid>
      <color>dialogFill1</color>  <!-- defined by keyref -->
    </solid>
  </fill>
</windowTheme>

If it were possible to impose a choice restriction on attributes I could do something like the following, but I am under the impression this is not possible with current (1.0) version of XSD spec.

<!-- I wish: -->
<xs:complexType name="colorType" >
  <xs:attrchoice>
    <xs:attribute name="value" type="HexLiteral" /> <!-- literal -->
    <xs:attribute name="ref" type="xs:string" />    <!-- keyref (defined elsewhere) -->
  </xs:attrchoice>
</xs:complexType>

Which would allow either lieral value or keyref ref:

<color value="0xFF0000" />     <!-- OK -->
<color ref="dialogBorder1" />  <!-- OK -->

But not both:

<color value="0xFF0000" ref="colorXYZ" /> <!-- NOT OK -->
  • 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-08T17:30:47+00:00Added an answer on June 8, 2026 at 5:30 pm

    The post is somewhat inconsistent in what’s describing. The first XML shows color used without attributes, then the xsd for colorType goes off with some attributes. I assume the XML is what you wanted.

    So the following works for:

    To define a color type that can either be a hexadecimal literal (such as 0xFF0000 for bright red) OR be a reference to a color defined elsewhere

        <xsd:simpleType name="ColorHex">
            <xsd:union memberTypes="xsd:string">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:pattern value="0x[0-9a-fA-F]{6}"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:union>
        </xsd:simpleType>
    

    The above uses the same pattern as the Color type in XHTML (I am showing this to give you sources of inspiration):

        <!-- sixteen color names or RGB color expression-->
        <xsd:simpleType name="Color">
            <xsd:union memberTypes="xsd:NMTOKEN">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:token">
                        <xsd:pattern value="#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:union>
        </xsd:simpleType>
    

    The idea here is to use a union. The downside may be that since all that’s not matching the HEX pattern will be matched by the string, invalid HEX syntax (e.g. missing digits) will pass through as references.

    Other downsides may be in how well is xsd:union supported by the programming languages that you’re targeting.

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

Sidebar

Related Questions

Is it possible to define an array of text fields (or any data type)
In ASP.NET MVC, is it possible to define routes that can determine which controller
In fortran 2003, is it possible to define a derived type which has a
Is it possible to write generic class with one constructor which explicitly defines type
In object type macro it is possible below, #define str this is a string
Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java
It's possible to define an alias in C# like this using kvp = System.Collections.Generic.KeyValuePair<string,
How to define a struct whose members can be accessed by any internal classes
Is it possible in C# to define return type of a method as some
I'd like to define a pointer type that is shared between device and host

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.