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="^[^><{}|^`\[\]\\\\]*$"/>
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.
Unlike stated in multiple comments and answers to this question, entities like > and < 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="[^><{}|^`\[\]\\\\]*"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
This will validate correctly:
<test>testing</test>
While these will not:
<test>{testing</test>
<test>>testing</test>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With