Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - Re: XSD Regular Expressions and empty content

 
Thread Tools Search this Thread
Old 06-27-2003, 10:49 AM   #1
Default Re: XSD Regular Expressions and empty content


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">
<xsattern 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">
> <xsdattern 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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump