XSD - another simple questions

Discussion in 'XML' started by Matthet, Sep 22, 2003.

  1. Matthet

    Matthet Guest

    Hello

    I've got simpleType restricted by pattern

    one element uses this simpleType
    and I would like
    another element to use this SimpleType
    but with one extra pattern.

    How to do it?

    I don't want to create second simpleType and
    use it with union to first simpleType.

    Thx for any help
    MAciek
     
    Matthet, Sep 22, 2003
    #1
    1. Advertising

  2. Matthet

    Bob Foster Guest

    "Matthet" <> wrote in message
    news:bkni4r$59b$...
    > I've got simpleType restricted by pattern
    >
    > one element uses this simpleType
    > and I would like
    > another element to use this SimpleType
    > but with one extra pattern.
    >
    > How to do it?


    There are two ways to do this. Derive a second simple type as a restriction
    of the first and put the pattern there, then use the second type for the
    other element, as in e2 below. Or define the second type anonymously in the
    definition of the element, as in e3 below.

    <xs:schema elementFormDefault="qualified" xml:lang="EN"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:simpleType name="t1">
    <xs:restriction base="xs:string">
    <xs:pattern value=".+"/>
    </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="t2">
    <xs:restriction base="t1">
    <xs:pattern value="[0-9]*"/>
    </xs:restriction>
    </xs:simpleType>
    <xs:element name="e1" type="t1"/>
    <xs:element name="e2" type="t2"/>
    <xs:element name="e3">
    <xs:simpleType>
    <xs:restriction base="t1">
    <xs:pattern value="[0-9]*"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    </xs:schema>

    In the example, type t1 disallows empty string contents, while type t2
    additionally restricts contents to the digits 0-9.

    Bob Foster
    http://www.xmlbuddy.com/
     
    Bob Foster, Sep 23, 2003
    #2
    1. Advertising

  3. Matthet

    Matthet Guest

    >"Bob Foster" wrote
    > ...
    > <xs:element name="e3">
    > <xs:simpleType>
    > <xs:restriction base="t1">
    > <xs:pattern value="[0-9]*"/>
    > </xs:restriction>
    > </xs:simpleType>
    > </xs:element>
    > </xs:schema>
    >



    Thanks,
    I thought I tried that
    but I've got problems with schema validation.

    Now it works OK.

    Thanks again
    MAciek
     
    Matthet, Sep 23, 2003
    #3
  4. Matthet

    Bob Foster Guest

    "Matthet" <> wrote in message
    news:bkq5t8$150k$...
    > Thanks,
    > I thought I tried that
    > but I've got problems with schema validation.


    That's easy to do when you're trying out this and that variant trying to get
    something to work.

    If you want an excellent book on XML Schema I recommend Priscilla Walmsley's
    "Definitive XML Schema". Google will find it.

    Bob Foster
    http://www.xmlbuddy.com/
     
    Bob Foster, Sep 26, 2003
    #4
    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. Markus
    Replies:
    1
    Views:
    1,108
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    491
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Replies:
    1
    Views:
    863
    Martin Honnen
    Jan 14, 2004
  4. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    794
    Peter Aberline
    Apr 5, 2004
  5. stiank81
    Replies:
    4
    Views:
    15,403
    stiank81
    Jun 26, 2005
Loading...

Share This Page