[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Allowing only a fixed length or empty for an element

From: Christopher Milton <cmiltonperl@yahoo.com>
Date: Wed, 6 Oct 2004 13:18:18 -0700 (PDT)
Message-ID: <20041006201818.5309.qmail@web20826.mail.yahoo.com>
To: Wilde Rebecca L SSgt HQ SSG/STS <Rebecca.Wilde@Gunter.AF.mil>, xmlschema-dev@w3.org
rebecca wilde

<xs:pattern value="([0-9]{4})?"/>

It's like Perl Regular Expressions:
? = 0 or 1
+ = 1 or more
* = 0 or more

^ and $ (beginning and end of string) are implicit,
unlike in Perl.

--- Wilde Rebecca L SSgt HQ SSG/STS <Rebecca.Wilde@Gunter.AF.mil> wrote:
> Hello,
> 
> I am trying to create a type that allows either a four position numeric
> or else must be an empty tag.
> 
> I.E. I want <Tag/> or <Tag>0045</Tag> to be valid, but I don't want
> <Tag>45</Tag> to be validated.
> 
> I've come up with the following to try and do this:
> 
> <xs:element name="Tag" type="TagType"/>
> <xs:simpleType name="TagType">
>   <xs:restriction base="xs:string">
>     <xs:pattern value="([0-9]{4})|[ ]{0}"/>
>   </xs:restriction>
> </xs:simpleType>
> 
> I'm using XMLSpy to help me as an editor for creating most of my work
> and validating it.  The above will allow me to validate/not validate as
> I desired, but when others try to use XMLSpy to validate against it as
> an empty tag, it comes back invalid.  
> 
> Is this a problem with XMLSpy, or is there a different way I should be
> trying to accomplish my goal?
> 
> Thank you!
> Becky
> 
Received on Wednesday, 6 October 2004 20:18:22 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.