Re: XSD Regular Expressions and empty content

Discussion in 'XML' started by Colin Mackenzie, Jun 27, 2003.

  1. Hi Chris,

    this can be acheived using xs:union to join two (or more) simple types
    together.
    Normally a truly empty type is created using an empty complexType but this
    cannot be used in a union AFAIK

    The schema snippet below is a union of your date type with an empty string
    type.

    <xs:element name="date" type="ESimpleDateType"/>
    <xs:simpleType name="ESimpleDateType">
    <xs:union memberTypes="SimpleDateType empty"/>
    </xs:simpleType>

    <xs:simpleType name="SimpleDateType">
    <xs:restriction base="xs:integer">
    <xs:pattern value="[0-9]{8}"/>
    </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="empty">
    <xs:restriction base="xs:string">
    <xs:maxLength value="0"/>
    </xs:restriction>
    </xs:simpleType>

    This seems to validate <date>12345678</date> and <date></date> and even
    <date/> (in MSXML 4 and XMLSpy)

    There may be a better way but I cant think of it for the moment.

    P.S. why are you using your own date type rather than the built in types?
    Your type will allow a dates including
    20030626 and
    26032003 not to mention
    20039999 and
    99992003

    Colin

    "Chris West" <> wrote in message
    news:bdh0r9$gnv$...
    > I want to restrict the content of an elements by declaring them of the
    > following type:
    >
    > <xsd:simpleType name="SimpleDateType">
    > <xsd:restriction base="xsd:integer">
    > <xsd:pattern value="[0-9]{8"/>
    > </xsd:restriction>
    > </xsd:simpleType>
    >
    > but I also want to allow empty content in xml instances, without using the
    > "nillable" attribute. Any suggestions?
    >
    > Thanks
    >
    > Chris
    >
    >
     
    Colin Mackenzie, Jun 27, 2003
    #1
    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. Jay Douglas
    Replies:
    0
    Views:
    644
    Jay Douglas
    Aug 15, 2003
  2. SW
    Replies:
    0
    Views:
    331
  3. Bernd Oninger
    Replies:
    1
    Views:
    563
    Henry S. Thompson
    Jun 30, 2004
  4. Replies:
    0
    Views:
    456
  5. Noman Shapiro
    Replies:
    0
    Views:
    262
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page