note 117995 added to domdocument.schemavalidate
| From: | mmamsch at googlemail dot com | Date: | Wed, 16 Sep 2015 10:01:59 +0000 |
| Subject: | note 117995 added to domdocument.schemavalidate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203790@lists.php.net to get a copy of this message | ||
A note for people trying to validate complex schemas with PHP. It seems that libxml will not
automatically try to import referenced schemas, but simply skip the validation if the schemas were
not explicitly imported.
In our example we tried to validate an XML file against a schema with the namespace
"xttp://automotive-his.de/200706/rif" that contains a reference to the namespace
"xttp://automotive-his.de/200706/rif-xhtml":
<xsd:complexType name="XHTML-CONTENT">
<xsd:sequence>
<xsd:any namespace="xttp://automotive-his.de/200706/rif-xhtml"/>
</xsd:sequence>
</xsd:complexType>
which basically says that an xhtml-content element can contain any element from the rif-xhtml
namespace.
However since libxml does not know where to find the schema file, it will stop the validation if the
elements from the referenced namespace, passing also document with invalid xhtml content as valid.
The solution was to create a combined schema, which contains import statements for all files
matching the referenced schemas:
<xsd:schema xmlns:xs="xttp://www.w3.org/2001/XMLSchema">
<xs:import namespace="xttp://automotive-his.de/200706/rif-xhtml"
schemaLocation="rif-xhtml.xsd"/>
<xs:import namespace="xttp://automotive-his.de/200706/rif"
schemaLocation="rif.xsd"/>
<xs:import namespace="xttp://www.w3.org/XML/1998/namespace"
schemaLocation="../xml.xsd"/>
</xsd:schema>
Note that the schemaLocation tells the validator, where to find the files for the corresponding
namespaces. When validating the XML document against this combined schema, libxml validated
correctly the content inside the XHTML-Content.
Hope this helps someone out there.
----
Server IP: 72.52.91.14
Probable Submitter: 195.125.180.132
----
Manual Page -- http://php.net/manual/en/domdocument.schemavalidate.php
Edit -- https://master.php.net/note/edit/117995
Del: integrated -- https://master.php.net/note/delete/117995/integrated
Del: useless -- https://master.php.net/note/delete/117995/useless
Del: bad code -- https://master.php.net/note/delete/117995/bad+code
Del: spam -- https://master.php.net/note/delete/117995/spam
Del: non-english -- https://master.php.net/note/delete/117995/non-english
Del: in docs -- https://master.php.net/note/delete/117995/in+docs
Del: other reasons-- https://master.php.net/note/delete/117995
Reject -- https://master.php.net/note/reject/117995
Search -- https://master.php.net/manage/user-notes.php