xs:pattern allows unallowed token

This should cover W3C XML Schema, Relax NG and DTD related problems.
SaschaF.
Posts: 13

xs:pattern allows unallowed token

Thu Mar 12, 2009 1:31 pm

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: 4144

Re: xs:pattern allows unallowed token

Thu Mar 12, 2009 5:37 pm

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

Re: xs:pattern allows unallowed token

Thu Mar 12, 2009 6:02 pm

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: 4144

Re: xs:pattern allows unallowed token

Thu Mar 12, 2009 6:16 pm

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

Re: xs:pattern allows unallowed token

Fri Mar 13, 2009 11:51 am

sorin wrote:The two patterns [...]

Args - Mea culpa! :?

Thanks sorin!

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 1 guest