Reputation: 55
I'm trying to validate an XML file with an XSD in PHP with DOMDocument
.
The translation
element must not appear in my XML but schemaValidate
does not return an error. I tested with the validation with another validation tool and it returns an error. I don't understand why schemaValidate
validates a bad XML.
a part of XSD
<xs:complexType name="CV">
<xs:complexContent>
<xs:restriction base="CE">
<xs:sequence>
<xs:element name="originalText" type="ED" minOccurs="0" maxOccurs="1">
<xs:annotation>
<xs:documentation>
The text or phrase used as the basis for the coding.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="translation" type="CD" minOccurs="0" maxOccurs="0"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
my XML
<?xml version="1.0"?>
<CV><translation/></CV>
my code
$dom = new DOMDocument("1.0","UTF-8");
$dom->loadXML("<?xml version=\"1.0\"?>
<CV><translation></translation></CV>");
echo $dom->schemaValidate("TestClasses.xsd");
for the complete XSD TestClasses.xsd
Thank for your help.
Upvotes: 1
Views: 174
Reputation: 25034
At first glance, this does look like a bug in the schema validator. The PHP manual suggests (but does not say explicitly) that schemaValidate() uses libxml. And libxml's XSD support is not yet complete.
For what it's worth, I note that commenting out the line
<xs:element name="translation" type="CD"
minOccurs="0" maxOccurs="0"/>
allows libxml to produce the correct result here, without invalidating the schema (as far as I can tell from a quick test with Saxon and Xerces J).
Upvotes: 2