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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:09:47+00:00 2026-06-05T11:09:47+00:00

I have an XSD file where I have defined a simple type restricted by

  • 0

I have an XSD file where I have defined a simple type restricted by an enumeration like this.

<xs:simpleType name="myEnumStrings">
    <xs:restriction base="xs:string">
        <xs:enumeration value="first"/>
        <xs:enumeration value="second"/>
        ...
        <xs:enumeration value="last"/>
    </xs:restriction>
</xs:simpleType>

I have a second simple type, the value of which depends on the possible values of the myEnumStrings in a complex way that I can describe only with a pattern.

<xs:simpleType name="patternRestrictedType">
    <xs:restriction base="xs:string">
        <xs:pattern value="..."/>
    </xs:restriction>
</xs:simpleType>

Currently I’m duplicating the information in the regular expression by using the string

(first|second|...|last)

whenever I want to refer to the myEnumStrings. This though is a trouble maker and a source of bugs because I need to keep all the regular expressions up to date when I modify the myEnumStrings type.

Is there a way to reference in the regular expression the possible values of the myEnumStrings to avoid this duplication? If this is not possible, is there a way to define globaly the string (first|second|…|last) to be reused in the regular expressions, to limit the duplication at only two places and to make the regular expressions more readable?

  • 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-05T11:09:49+00:00Added an answer on June 5, 2026 at 11:09 am

    XSD is not good at it, as in “elegant”. The only things that might help is the use of unions; it would work based on your specific pattern, but it may not work based on something else you did not describe.

    The idea is to reuse enumerations. To do that, you create simple types that encapsulate the enums you wish to reuse. Just an observation, having more than one enumerated values is technically equivalent with a disjunction of its values (in terms of patterns).

    <?xml version="1.0" encoding="utf-8" ?>
    <xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:simpleType name="myEnumStrings-1">
            <xsd:restriction base="xsd:string">
                <xsd:enumeration value="first"/>
            </xsd:restriction>
        </xsd:simpleType>
        <xsd:simpleType name="myEnumStrings-2">
            <xsd:restriction base="xsd:string">
                <xsd:enumeration value="second"/>
            </xsd:restriction>
        </xsd:simpleType>
        <xsd:simpleType name="myEnumStrings-n">
            <xsd:restriction base="xsd:string">
                <xsd:enumeration value="last"/>
            </xsd:restriction>
        </xsd:simpleType>
    
        <xsd:simpleType name="myEnumStrings">
            <xsd:union memberTypes="myEnumStrings-1 myEnumStrings-2 myEnumStrings-n"/>
        </xsd:simpleType>
    
        <xsd:simpleType name="patternRestrictedType">
            <xsd:union memberTypes="myEnumStrings-1 myEnumStrings-2"/>
        </xsd:simpleType>
    
        <xsd:element name="root-a" type="myEnumStrings"/>
        <xsd:element name="root-b" type="patternRestrictedType"/>
    </xsd:schema>
    

    The above achieves the reuse of enumerations, or anything else you define as constraints for union members.

    Valid XML for root-a:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
    <root-a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd">last</root-a>
    

    Valid XML for root-b:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
    <root-b xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd">second</root-b>
    

    While root-b’s content will work for root-a, the reverse is not true.

    As I said, maybe not that elegant when you think big sets; it should however, strictly answer what I think you asked and may give you pointers for other approaches.

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

Sidebar

Related Questions

I have defined a enum as below in the XSD file <xs:simpleType name=PaperSizes> <xs:restriction
In an xsd file I have this element base type : <xs:complexType name=event abstract=true
I have a XSD file like below: <element name=finder-def minOccurs=0 maxOccurs=unbounded> <complexType> <attribute name=name
I have this Maven task to generate Java classes from an XSD file using
I have defined schema for xml in file packetTemplate.xsd.Using ms tool xsd.exe i have
I have xml file whose structure is defined with following xsd: <?xml version=1.0 encoding=utf-8?>
I have several elements defined in my XSD file that I use as references
I have some common types which are defined in an xsd file which is
I have a mvc.SiteMap defined something like this: <mvcSiteMap xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns=http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0 xsi:schemaLocation=http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0 MvcSiteMapSchema.xsd enableLocalization=true
I have one xsd file I'd rather not modify (Exceptions.xsd): <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns=http://me.com/Exceptions.xsd targetNamespace=http://me.com/Exceptions.xsd

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.