xs:pattern allows unallowed token

This should cover W3C XML Schema, Relax NG and DTD related problems.
SaschaF.
Posts: 13
Joined: Wed Oct 29, 2008 9:32 am

xs:pattern allows unallowed token

Post by SaschaF. »

Hello.

I defined the following pattern for evaluating a date-string:

Code: Select all


([0-9]{4}\-[0-9]{1,2}\-[0-9]{1,2})?
IMHO this should only allow something like 2009-03-12 or nothing!

But the XML-Validation (all engines) allows the following chars: a, e, n, p, r and t

i.e.

Code: Select all


<tag>a</tag>
is allowed.

Whats that :?: :?:

Btw: Oxygens inplaced RegEx-Konstruktor does not have this behavior.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: xs:pattern allows unallowed token

Post by sorin_ristache »

Hello,

I tested your pattern in Oxygen both in the XML Schema regex builder tool (available on the Tools menu) and in an XML document validated against an XML Schema that specifies the pattern. It works correctly. Illegal characters like a, e, n, p, etc are reported as error. Can you post a sample schema for reproducing the problem?


Regards,
Sorin
SaschaF.
Posts: 13
Joined: Wed Oct 29, 2008 9:32 am

Re: xs:pattern allows unallowed token

Post by SaschaF. »

XSD

Code: Select all

?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TEST">
<xs:complexType>
<xs:sequence>
<xs:element name="FIELDVALUE">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[pattern]"/>
<xs:pattern value="(\d{4}\-\d{1,2}\-\d{1,2})?"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<TEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Test.xsd">
<FIELDVALUE>a</FIELDVALUE>
</TEST>
<oXygen/> XML Editor 10.1, build 2009022414
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: xs:pattern allows unallowed token

Post by sorin_ristache »

SaschaF. wrote:

Code: Select all

<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[pattern]"/>
<xs:pattern value="(\d{4}\-\d{1,2}\-\d{1,2})?"/>
</xs:restriction>
</xs:simpleType>
The two patterns are ORed, not ANDed which means the following values are accepted: p, a, t, e, r, n, 2009-03-12, 1863-3-6, etc.


Regards,
Sorin
SaschaF.
Posts: 13
Joined: Wed Oct 29, 2008 9:32 am

Re: xs:pattern allows unallowed token

Post by SaschaF. »

sorin wrote: The two patterns [...]
Args - Mea culpa! :?

Thanks sorin!
Post Reply