The value of '<! \ [CDATA \ [. *? \] \]> | [^ <> &] * 'Facet template' is not a valid regular expression

I am trying to use a regex to validate a field in my xml using xsd. I came up with a regular expression to do what I want to prohibit special characters if the text is not wrapped in CDATA tags. This is the regex that I came up with:

<!\[CDATA\[.*?\]\]>|[^<>&]*

Works great when I test it at http://regexr.com/ to fit my pattern. The problem is that when I try to connect it to a simple template template, I get an error message that is not a valid regular expression.

The value '<!\[CDATA\[.*?\]\]>|[^<>&]*' of the facet 'pattern' is not a valid regular expression.

Here is my xsd code (note that I had to replace & <> in the regex with &lt; &gt;and &amp;, so it will be valid xml):

<xs:element name="description" minOccurs="1" maxOccurs="1">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:pattern value="&lt;!\[CDATA\[.*?\]\]&gt;|[^&lt;&gt;&amp;]*"/>          
        </xs:restriction>
    </xs:simpleType>
</xs:element>

So, I guess there is something about how regex works in xsd samples that I don't get.

0
source share
1 answer

As an exception, I was able to find a fix. First, I determined that the problem is somewhere in the <!\[CDATA\[.*?\]\]>expression part . So I ripped it out of my expression and slowly added bits back until I got the same error. The character that caused the problem was ?. An expression still works without ?, even if there is nothing inside CDATA.

1) , , , 2) xsd ?

0

Source: https://habr.com/ru/post/1783886/


All Articles