Question

Why does xmllint not report validation failure for the following xsd and xml ?

t.xsd

<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="letter">
   <xs:simpleType>
      <xs:restriction base="xs:string">
      <xs:pattern value="([a-z])+"/>
      </xs:restriction>
   </xs:simpleType>
</xs:element>
</xs:schema>

t.xml

 <letter></letter>

$ ./xmllint --schema t.xsd t.xml

<?xml version="1.0"?>
<letter/>
t1.xml validates
Was it helpful?

Solution

The input does not look valid to me (Mark O'Connor says it's valid, but I don't see any argument to that effect, just a bald statement). Equally to the point, it doesn't look valid to Xerces J or to Saxon EE.

The XSD support in xmllint is known to be a bit spotty, but mostly that means that there are parts of the spec that aren't supported; this looks more like a straightforward bug in the regex routine. I see several unresolved regex bugs in the gnome bugtracker for libxml; perhaps this is related. I've opened a new bug report with this issue.

OTHER TIPS

The input is valid. You need to add an additional restriction on length.... Call it a "feature" of XML Schema :-)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="letter">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:pattern value="([a-z])+"/>
        <xs:minLength value="1"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>

Update

Revised the schema as follows and then it appears to work as you're expecting

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="letter">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:pattern value="[a-z]+"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top