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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:05:53+00:00 2026-06-14T23:05:53+00:00

I need to define an element with multiple patterns, like gDay , gMonth ,

  • 0

I need to define an element with multiple patterns, like gDay, gMonth, gYear, dateTime, etc. How can I define a restriction in XSD to do that?

Someting like this:

<dates>
    <out>2012</out>
</dates>


<xs:complexType name="infodates">
        <xs:sequence>
            <xs:element name="out" type="xs:dateTime"&"xs:gMonth"/>
        </xs:sequence>
</xs:complexType>

Thanks

  • 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-14T23:05:54+00:00Added an answer on June 14, 2026 at 11:05 pm

    Short answer: xml schema can’t concatenate simple datatypes.

    It might not be what you want anyway: xs:gMonth requires a double-hyphen prefix (e.g. “–05”), and xs:gDay needs a triple-hyphen (e.g. “—31”). Not what I expected!
    Here’s examples for each simple datatype. There’s some combined types built-in too: gYearMonth, gMonthDay etc.

    Along these lines, xs:dateTime has a long definition: '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)? Only three parts can be left out, so it needs yyyy-mm-ddThh:mm:ss – your example in <out>2012</out> isn’t valid with respect to this.


    Long answer: However, xml schema can combine simple datatypes by union (like choice) and list (space-separated list of the same type). So, you can do something like: (gDay|gMonth|gYear|dateTime)* (not valid xsd syntax, just illustrative). This isn’t ordered and allows duplicates, so e.g. “—31 –05 –05” is valid. Here it is in xsd syntax:

    $ cat catDatatypes.xsd 
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="eg" type="myString_Type"/>
      <xs:simpleType name="myString_Type">
        <xs:list>
          <xs:simpleType>
            <xs:union>
              <xs:simpleType>
                <xs:restriction base="xs:gDay"/>
              </xs:simpleType>
              <xs:simpleType>
                <xs:restriction base="xs:gMonth"/>
              </xs:simpleType>
              <xs:simpleType>
                <xs:restriction base="xs:gYear"/>
              </xs:simpleType>
              <xs:simpleType>
                <xs:restriction base="xs:dateTime"/>
              </xs:simpleType>
            </xs:union>
          </xs:simpleType>
        </xs:list>
      </xs:simpleType>
    </xs:schema>
    
    $ xmllint --schema catDatatypes.xsd catDatatypes.xml 
    <eg>2012 --12 ---01 --12 ---31 --05 --05</eg>
    catDatatypes.xml validates
    

    Conclusion: You can’t reuse the built-in datatypes in the way you (and I) would like, and they don’t seem very nice anyway. You’re probably better off explicitly defining it yourself, as in InfantProgrammer’Aravind’s answer. (Or, you could use separate attributes for each component instead – which would make it easier for whoever is parsing it, too).


    For fun, I tried shortening InfantProgrammer’Aravind’s answer (though it’s arguable whether this makes it clearer…). It retains the check of 12-hour with am/pm vs. 24-hour without am/pm (but doesn’t accept empty aka null value).

     <xs:simpleType name="CRNDATETIME2">
        <xs:restriction base="xs:string">
          <xs:pattern value="(0[1-9]|1[012])/(0[1-9]|[12]\d|3[01])/([12]\d{3}) ((0\d|1[012])(:[0-5]\d){2}|(0\d|1[012])(:[0-5]\d){2} [aApP][mM])"/>
        </xs:restriction>
      </xs:simpleType>
    

    Here’s a brief guide to regex in XSD; here’s a long one.

    BTW: Turns out you can denote “[1-9]” as “[\d-[0]]”, which is a “Character Class Subtraction“, not a range.

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

Sidebar

Related Questions

I need to define multiple modules in the same file. I would like to
I am defining an XSD. I need to define an element which takes date
I need to define a template struct such that: element<T>::type is of type: T::element_type
I need to define a Structuring Element of a mask size 30 by 105
I need to define the constant in the module that use the method from
I need to define a Wix file component that may not exist in certain
I need to define an appender for log4net in a way that I get
I need to define some constant strings that will be used only by one
Although appengine already is schema-less, there still need to define the entities that needed
I'm using extended types in my XSD for common element sequences I need in

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.