Element with maxlength restriction, with two attributes

Discussion in 'XML' started by executeinc@gmail.com, Oct 18, 2007.

  1. Guest

    Could you some help to define
    1. An element with restriction on it's base type (xs:string), limiting
    maxlength
    2. That element also needs two attributes defined on it.

    Simple restriction is easy:
    <xs:element name="kirk" minOccurs="0" maxOccurs="1">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:maxLength value="2"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>

    But doesn't allow for the attribute definition. I've tried
    complexcontent, etc. and can't quite get it.

    Help?
     
    , Oct 18, 2007
    #1
    1. Advertising

  2. Guest

    On 18 Oct, 15:04, wrote:
    > Could you some help to define
    > 1. An element with restriction on it's base type (xs:string), limiting
    > maxlength
    > 2. That element also needs two attributes defined on it.
    >
    > Simple restriction is easy:
    > <xs:element name="kirk" minOccurs="0" maxOccurs="1">
    > <xs:simpleType>
    > <xs:restriction base="xs:string">
    > <xs:maxLength value="2"/>
    > </xs:restriction>
    > </xs:simpleType>
    > </xs:element>
    >
    > But doesn't allow for the attribute definition. I've tried
    > complexcontent, etc. and can't quite get it.
    >
    > Help?


    You need to do this in two steps. First define a simple type that has
    a climited length string, and then another type that adds the two
    attributes to it.

    e.g.
    <xs:simpleType name="shortString">
    <xs:restriction base="xs:string">
    <xs:maxLength value="2"/>
    </xs:restriction>
    </xs:simpleType>

    <xs:element name="kirk" minOccurs="0" maxOccurs="1">
    <xs:complexType>
    <xs:simpleContent>
    <xs:extension base='shortString'>
    <xs:attribute name='a1' type='xs:int'/>
    <xs:attribute name='a2' type='xs:int'/>
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>
    </xs:element>

    Ah, the beauty of XML schema - not!

    HTH,

    Pete.
    =============================================
    Pete Cordell
    Codalogic
    for XML Schema to C++ data binding visit
    http://www.codalogic.com/lmx/
    =============================================
     
    , Oct 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Howden
    Replies:
    0
    Views:
    509
    Andy Howden
    Oct 20, 2003
  2. Replies:
    0
    Views:
    357
  3. Grisha Golberg
    Replies:
    0
    Views:
    364
    Grisha Golberg
    Mar 3, 2004
  4. Replies:
    1
    Views:
    446
    Priscilla Walmsley
    Jun 14, 2006
  5. PeteOlcott
    Replies:
    1
    Views:
    950
    Mukul Gandhi
    Feb 5, 2009
Loading...

Share This Page