XSD restrictions - both string and numerical

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • voorth

    #1

    XSD restrictions - both string and numerical

    I was wondering if it is possible to define an restricted attribute
    such that the following forms are both valid:

    <myElement value="hi"/<!-- value should be "hi" or "lo" -->
    <myElement value="100"/><!-- value should be between 50-150 -->

  • Martin Honnen

    #2
    Re: XSD restrictions - both string and numerical

    voorth wrote:
    I was wondering if it is possible to define an restricted attribute
    such that the following forms are both valid:
    >
    <myElement value="hi"/<!-- value should be "hi" or "lo" -->
    <myElement value="100"/><!-- value should be between 50-150 -->
    You can define a union type of two simple types:

    <xs:attribute name="value">
    <xs:simpleTyp e>
    <xs:union>
    <xs:simpleTyp e>
    <xs:restricti on base="xs:string ">
    <xs:enumerati on value="hi"/>
    <xs:enumerati on value="lo"/>
    </xs:restriction>
    </xs:simpleType>
    <xs:simpleTyp e>
    <xs:restricti on base="xs:int">
    <xs:minInclusiv e value="50"/>
    <xs:maxInclusiv e value="100"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:union>
    </xs:simpleType>
    </xs:attribute>

    See section "2.5.1.3 Union datatypes" in
    <URL:http://www.w3.org/TR/xmlschema-2/#datatype-dichotomies>
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • usenet@tech-know-ware.com

      #3
      Re: XSD restrictions - both string and numerical

      On 12 Feb, 11:33, voorth <voo...@xs4all. nlwrote:
      I was wondering if it is possible to define an restricted attribute
      such that the following forms are both valid:
      >
      <myElement value="hi"/<!-- value should be "hi" or "lo" -->
      <myElement value="100"/><!-- value should be between 50-150 -->
      You can use XML schema xs:union construct to do this. Something along
      the lines of:

      <xs:attribute name="value">
      <xs:simpleTyp e>
      <xs:union>
      <xs:simpleTyp e>
      <xs:restricti on base="xs:int">
      <xs:minInclusiv e value="50"/>
      <xs:maxInclusiv e value="150"/>
      </xs:restriction>
      </xs:simpleType>
      <xs:simpleTyp e>
      <xs:restricti on base="xs:string ">
      <xs:enumerati on value="hi"/>
      </xs:restriction>
      </xs:simpleType>
      </xs:union>
      </xs:simpleType>
      </xs:attribute>

      Although you probably don't want the string part as restricted as
      this!

      HTH,

      Pete Cordell
      Codalogic
      Visit http://www.codalogic.com/lmx/ for XML C++ data binding

      Comment

      • usenet@tech-know-ware.com

        #4
        Re: XSD restrictions - both string and numerical

        On 12 Feb, 12:41, use...@tech-know-ware.com wrote:
        On 12 Feb, 11:33, voorth <voo...@xs4all. nlwrote:
        >
        I was wondering if it is possible to define an restricted attribute
        such that the following forms are both valid:
        >
        ...
        >
        Although you probably don't want the string part as restricted as
        this!
        Ooops, missed the 'lo' part. See Martin's answer for that. He must
        type faster than me!

        HTH,

        Pete Cordell
        Codalogic
        Visit http://www.codalogic.com/lmx/ for XML C++ data binding

        Comment

        • voorth

          #5
          Re: XSD restrictions - both string and numerical

          Thanks, guys, that was just what I was looking for.

          Comment

          Working...