nveo
nveo

Reputation: 401

XML Schema Validation Pattern Restriction Error

I have the following files:

a.xml

<?xml version="1.0"?>
<e xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="a.xsd">
  2
</e>

a.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="e">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>
</xs:schema>

and when validating i get:

Error:(4, 5) cvc-pattern-valid: Value ' 2 ' is not facet-valid with respect to pattern '[0-9]' for type '#AnonType_e'.

What am i doing wrong?

Upvotes: 0

Views: 517

Answers (1)

Michael Kay
Michael Kay

Reputation: 163458

You could either change the pattern to allow the surrounding whitespace, or you could add a whitespace facet (="collapse") to force the whitespace to be ignored before the pattern is applied.

Upvotes: 1

Related Questions