3

I am trying to validate a XML element with XSD pattern validation using below pattern and it's not working. The required behavior is to allow all characters excepts the ones mentioned in pattern expression.

<xsd:pattern value="^[^&gt;&lt;{}|^`\[\]\\\\]*$"/>

Valid data : TESTING
Invalid data : TE{ST]`I<NG

But above pattern is giving validation error for valid data(TESTING) also in XSD but same works fine if I use this pattern in java regualr expression match package. Please help.

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
springenthusiast
  • 403
  • 1
  • 8
  • 30

1 Answers1

5

Unlike stated in multiple comments and answers to this question, entities like &gt; and &lt; can be used without any problems in XML Schema regular expressions.

However, anchors like the caret (^) and dollar ($) are not supported.

Given the following schema, with the anchors removed from the pattern:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > 
  <xsd:element name="test" type="test"/> 

  <xsd:simpleType name="test"> 
    <xsd:restriction base="xsd:string"> 
      <xsd:pattern value="[^&gt;&lt;{}|^`\[\]\\\\]*"/> 
    </xsd:restriction> 
  </xsd:simpleType> 
</xsd:schema>

This will validate correctly:

<test>testing</test>

While these will not:

<test>{testing</test>

<test>&gt;testing</test>
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156