how to use restrictions and extensions in XSD simultanously

Discussion in 'XML' started by Dmitry Kulinich, Feb 19, 2007.

  1. Guys! I've got 1 more small problem with XSD. It simple and good, but
    sometimes disappointing.
    For example we have 3 <TH> tags - only text and 1 attribute.
    Then we need <restriction>-<enumeration> to set all <th>'s text values, but
    also <extension> to add 1 attribute
    How to do it simultanously inside og 1 element?
    Here is simple code in XSD:
    <xsd:element name="TH" >

    <xsd:complexType>

    <xsd:simpleContent>

    <xsd:extension base="xsd:string">

    <!--xsd:restriction base="xsd:string">

    <xsd:enumeration value="Process ID"/>

    <xsd:enumeration value="Activity ID"/>

    <xsd:enumeration value="Instance ID"/>

    <xsd:enumeration value="Process Description"/>

    </xsd:restriction-->

    <xsd:attribute name="style" type="xsd:string" />

    </xsd:extension>


    </xsd:simpleContent>


    </xsd:complexType>

    </xsd:element>


    --
    Thank you,
    De Cool,
    EPE
    Dmitry Kulinich, Feb 19, 2007
    #1
    1. Advertising

  2. Dmitry Kulinich

    Guest

    On 19 Feb, 21:48, "Dmitry Kulinich" <> wrote:

    > For example we have 3 <TH> tags - only text and 1 attribute.
    > Then we need <restriction>-<enumeration> to set all <th>'s text values, but
    > also <extension> to add 1 attribute


    In XSD schema you have to do it in two stages. Define the body type
    of the TH element (as a simple type), and then extend it to add the
    attribute. e.g.:

    <xsd:simpleType name="THType">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value="Process ID"/>
    <xsd:enumeration value="Activity ID"/>
    <xsd:enumeration value="Instance ID"/>
    <xsd:enumeration value="Process Description"/>
    </xsd:restriction>
    </xsd:simpleType>

    <xsd:element name="TH" >
    <xsd:complexType>
    <xsd:simpleContent>
    <xsd:extension base="THType">
    <xsd:attribute name="style" type="xsd:string" />
    </xsd:extension>
    </xsd:simpleContent>
    </xsd:complexType>
    </xsd:element>

    HTH,

    Pete.
    =============================================
    Pete Cordell
    Tech-Know-Ware Ltd
    for XML to C++ data binding visit
    http://www.tech-know-ware.com/lmx
    (or http://www.xml2cpp.com)
    =============================================
    , Feb 20, 2007
    #2
    1. Advertising

  3. Dmitry Kulinich

    Guest

    Original Message From: "Dmitry Kulinich"
    >
    > Thank you, Pete! It's really simple )))
    > Could you answer one more question please - how to define few <td> tags with
    > different types
    > (means - tags with the same name but with the different type. A've tried to
    > set node type in restrictions but it doesn't works )



    If the types are all simple types, then you can use schema's xs:union
    construct. e.g.:

    <xs:simpleType name="TDType">
    <xs:union memberTypes="xs:float xs:int xs:string"/>
    </xs:simpleType>

    Normally you would put the most restricted type first, followed by
    progressively less restricted types. i.e. all integers could be
    represented in a string, but not all strings are valid integers.

    If you want different complex types, thn I'm afraid you are out of
    luck with XSD schema as it is defined today!

    HTH,

    Pete.
    --
    =============================================
    Pete Cordell
    Tech-Know-Ware Ltd
    for XML to C++ data binding visit
    http://www.tech-know-ware.com/lmx
    (or http://www.xml2cpp.com)
    =============================================
    , Feb 20, 2007
    #3
  4. Dmitry Kulinich

    Guest

    On 20 Feb, 15:29, wrote:
    > Original Message From: "Dmitry Kulinich"
    >
    > > Thank you, Pete! It's really simple )))
    > > Could you answer one more question please - how to define few <td> tags with
    > > different types
    > > (means - tags with the same name but with the different type. A've tried to
    > > set node type in restrictions but it doesn't works )

    >
    > If the types are all simple types, then you can use schema's xs:union
    > construct. e.g.:
    >
    > <xs:simpleType name="TDType">
    > <xs:union memberTypes="xs:float xs:int xs:string"/>
    > </xs:simpleType>
    >
    > Normally you would put the most restricted type first, followed by
    > progressively less restricted types. i.e. all integers could be
    > represented in a string, but not all strings are valid integers.


    Ooops - which means I should flip xs:int and xs:float around! e.g.

    <xs:simpleType name="TDType">
    <xs:union memberTypes="xs:int xs:float xs:string"/>
    </xs:simpleType>

    Just testing!!!

    Pete.
    =============================================
    Pete Cordell
    Tech-Know-Ware Ltd
    for XML to C++ data binding visit
    http://www.tech-know-ware.com/lmx
    (or http://www.xml2cpp.com)
    =============================================
    , Feb 20, 2007
    #4
  5. unfortunately I needed this solution 4 the complex type
    anyhow, thank you very mush!!!
    <> wrote in message
    news:...
    > On 20 Feb, 15:29, wrote:
    >> Original Message From: "Dmitry Kulinich"
    >>
    >> > Thank you, Pete! It's really simple )))
    >> > Could you answer one more question please - how to define few <td> tags
    >> > with
    >> > different types
    >> > (means - tags with the same name but with the different type. A've
    >> > tried to
    >> > set node type in restrictions but it doesn't works )

    >>
    >> If the types are all simple types, then you can use schema's xs:union
    >> construct. e.g.:
    >>
    >> <xs:simpleType name="TDType">
    >> <xs:union memberTypes="xs:float xs:int xs:string"/>
    >> </xs:simpleType>
    >>
    >> Normally you would put the most restricted type first, followed by
    >> progressively less restricted types. i.e. all integers could be
    >> represented in a string, but not all strings are valid integers.

    >
    > Ooops - which means I should flip xs:int and xs:float around! e.g.
    >
    > <xs:simpleType name="TDType">
    > <xs:union memberTypes="xs:int xs:float xs:string"/>
    > </xs:simpleType>
    >
    > Just testing!!!
    >
    > Pete.
    > =============================================
    > Pete Cordell
    > Tech-Know-Ware Ltd
    > for XML to C++ data binding visit
    > http://www.tech-know-ware.com/lmx
    > (or http://www.xml2cpp.com)
    > =============================================
    >
    >
    >
    Dmitry Kulinich, Feb 21, 2007
    #5
  6. Dmitry Kulinich

    Guest

    On 21 Feb, 08:31, "Dmitry Kulinich" <> wrote:
    > unfortunately I needed this solution 4 the complex type
    > anyhow, thank you very mush!!!
    >
    > >> Original Message From: "Dmitry Kulinich"

    >
    > >> > Thank you, Pete! It's really simple )))
    > >> > Could you answer one more question please - how to define few <td> tags
    > >> > with
    > >> > different types
    > >> > (means - tags with the same name but with the different type. A've
    > >> > tried to
    > >> > set node type in restrictions but it doesn't works )


    Then I'm afraid, as far as XSD schema is concerned, you are left with
    defining the superset of all the types.

    Some people add schematron constraints to the XSD definition to select
    the correct forms at runtime, but I'm not sure many tools support that
    approach.

    Relax-NG, an alternative schema language, has support for this sort of
    thing, but I'm not sure how widely supported that is either (libxml2
    has some support for it).

    HTH,

    Pete.
    --
    =============================================
    Pete Cordell
    Tech-Know-Ware Ltd
    for XML to C++ data binding visit
    http://www.tech-know-ware.com/lmx
    (or http://www.xml2cpp.com)
    =============================================
    , Feb 21, 2007
    #6
    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. =?Utf-8?B?U2l2YXJhbWFuLlM=?=

    How to execute a aspx page more than once simultanously?

    =?Utf-8?B?U2l2YXJhbWFuLlM=?=, Oct 14, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    372
    John Saunders
    Oct 15, 2004
  2. Bernd Oninger
    Replies:
    1
    Views:
    514
    Henry S. Thompson
    Jun 30, 2004
  3. TIANA

    Restrictions in XSD

    TIANA, Dec 7, 2004, in forum: XML
    Replies:
    0
    Views:
    408
    TIANA
    Dec 7, 2004
  4. voorth
    Replies:
    4
    Views:
    448
    voorth
    Feb 12, 2008
  5. Arinté

    XSD restrictions/extensions

    Arinté, Dec 18, 2008, in forum: XML
    Replies:
    0
    Views:
    744
    Arinté
    Dec 18, 2008
Loading...

Share This Page