Note that there are some explanatory texts on larger screens.

plurals
  1. POLibXML2 date validation errors with regular expression
    primarykey
    data
    text
    <p>I have a problem while validating XML against schema that uses regular expression. I'm using LibXML. Actually the libXML is used by PHP, but same problem, of course, occurs in the console. XML should be valid since I tested it with some online validators.</p> <p>Anyway workarounds? Modifying the schema is not a very good option because it's provided by a third party source.</p> <p>I'm using xmllint command with libXML versions 2.7.8 and 2.9.1. </p> <pre><code>xmllint: using libxml version 20708 compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib xmllint: using libxml version 20901 compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib </code></pre> <p><strong>Command I use:</strong></p> <pre><code> xmllint --noout -schema s x </code></pre> <p><strong>Errors I get:</strong></p> <pre><code>x:2: element testdate: Schemas validity error : Element 'testdate': [facet 'pattern'] The value '31.8.2013' is not accepted by the pattern '((([0-2]{0,1}[0-9]{1})|(3[0,1]{1}))\.((0?[1-9]{1})|(1[0-2]{1}))\.2[0-9]{3})?'. x:2: element testdate: Schemas validity error : Element 'testdate': '31.8.2013' is not a valid value of the atomic type 'mdatetype'. x fails to validate </code></pre> <p><strong>My XML file named 'x' is:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;testdate&gt;31.8.2013&lt;/testdate&gt; </code></pre> <p><strong>My schema named 's' is:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:element name="testdate" type="mdatetype"/&gt; &lt;xs:simpleType name="mdatetype"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:maxLength value="10"/&gt; &lt;xs:pattern value="((([0-2]{0,1}[0-9]{1})|(3[0,1]{1}))\.((0?[1-9]{1})|(1[0-2]{1}))\.2[0-9]{3})?"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:schema&gt; </code></pre> <p><strong>Edit</strong></p> <p>Some regular expressions work. I tested with finnish sosial security numbers</p> <p><strong>Schema</strong></p> <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:element name="x" /&gt; &lt;xs:element name="testdate" type="mdatetype" /&gt; &lt;xs:element name="testhetu" type="mhetu" /&gt; &lt;xs:simpleType name="mdatetype"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:pattern value="((([0-2]{0,1}[0-9]{1})|(3[0,1]{1}))\.((0?[1-9]{1})|(1[0-2]{1}))\.2[0-9]{3})?"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;xs:simpleType name="mhetu"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:pattern value="((([0-2]{1}[0-9]{1})|(3[0,1]{1}))((0[0-9]{1})|(1[0-2]{1}))[0-9]{2}[\+\-aA]{1}[0-9]{3}[0-9A-Fa-fHhJ-Nj-nPpR-Yr-y]{1})?"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:schema&gt; </code></pre> <p><strong>XML</strong></p> <pre><code>&lt;x&gt; &lt;testhetu&gt;151182-152x&lt;/testhetu&gt; &lt;testhetu&gt;151182A154G&lt;/testhetu&gt; &lt;/x&gt; </code></pre> <p>*<em>Result (only the latest SSN is invalid, since G is not allowed) *</em></p> <pre><code>x:3: element testhetu: Schemas validity error : Element 'testhetu': [facet 'pattern'] The value '151182A154G' is not accepted by the pattern '((([0-2]{1}[0-9]{1})|(3[0,1]{1}))((0[0-9]{1})|(1[0-2]{1}))[0-9]{2}[\+\-aA]{1}[0-9]{3}[0-9A-Fa-fHhJ-Nj-nPpR-Yr-y]{1})?'. x:3: element testhetu: Schemas validity error : Element 'testhetu': '151182A154G' is not a valid value of the atomic type 'mhetu'. x fails to validate </code></pre> <p>Any help is welcome!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload