users@jaxb.java.net

Re: Request clarification using regular expressions within simple types

From: Pete Hendry <peter.hendry_at_capeclear.com>
Date: Tue, 26 Aug 2003 17:48:27 +1200

Facets such as pattern, length, minLength, maxLength, totalDigits,
fractionDigits should be applied to the string value before it is parsed
I believe. That is why Xerces says it's valid (because it is). It does
not make sense to do it another way.

Pete

James Henderson wrote:

>I'm using a regular expression within a simple type to restrict the simple
>type. The reason I am doing this is to provide an optional 5 digit
>extension associated with a phone number.
>
>However when I use the value 00000 for the extension and use JAXB to
>validate the XML document, the validation will fail with the following
>message:
>
>[ERROR]: the value does not match the regular expression "\d{5}".
>
>This problem does not happen if I use the value 11111 for the extension.
>
>
>What is the correct behavior in this situation?
>a) The value is converted to integer and then evaluated as a regular
>expression (meaning that JAXB validation is correct)
>b) The value should be evaluated as a regular expression and then converted
>to an integer (meaning that JAXB validation is incorrect)
>
>[As a side not Apache Xerces indicates that the XML document is valid.]
>
>
>XSD and XML document follow:
>
>BusinessData.xsd
>================
><?xml version="1.0" encoding="UTF-8"?>
><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>elementFormDefault="unqualified" attributeFormDefault="unqualified">
> <xs:element name="BusinessData">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="phone"
>type="ctPhoneNumber"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:complexType name="ctBusinessDefinition" />
> <xs:complexType name="ctPhoneNumber">
> <xs:annotation>
> <xs:documentation>Describes a phone number in the
>system.</xs:documentation>
> </xs:annotation>
> <xs:complexContent>
> <xs:extension base="ctBusinessDefinition">
> <xs:sequence>
> <xs:element name="number"
>type="stPhoneNumber">
> <xs:annotation>
>
> <xs:documentation>Describes the phone number. </xs:documentation>
> </xs:annotation>
> </xs:element>
> <xs:element name="extension"
>minOccurs="0">
> <xs:annotation>
>
> <xs:documentation>Describes the phone extension. </xs:documentation>
> </xs:annotation>
> <xs:simpleType>
> <xs:restriction
>base="xs:int">
> <xs:pattern
>value="\d{5}"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
> <xs:simpleType name="stPhoneNumber">
> <xs:annotation>
> <xs:documentation>Describes a phone number.
></xs:documentation>
> </xs:annotation>
> <xs:restriction base="xs:string">
> <xs:pattern value="\d{3}-\d{3}-\d{4}"/>
> <xs:pattern value="(\d{3})-\d{3}-\d{4}"/>
> </xs:restriction>
> </xs:simpleType>
></xs:schema>
>
>
>
>
>
>BusinessDataSample.xml
>======================
><?xml version="1.0" encoding="UTF-8"?>
><BusinessData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>xsi:noNamespaceSchemaLocation="BusinessData.xsd">
> <phone>
> <number>000-000-0000</number>
> <extension>00000</extension>
> </phone>
></BusinessData>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net