Process XML directories by php

I have an XSD (XML Schema) that contains several files. At the root of the system is the .xml directory, which is the XML directory. It contains the SYSTEM directory and URI directory definitions that are necessary for the proper handling of xsd files.

Now my question is: how can I check xml for these schemes in php? If I just use DOMDocument-> Schemavalidate () and give it the correct xsd, the directory definitions will not be resolved, and php throws an error similar to this:

Warning: DOMDocument::schemaValidate(): I/O warning : failed to load external entity "urn:oasis:names:tc:dita:xsd:highlightDomain.xsd:1.2" 

This is in the catalog.xml file how to resolve this expression, but I could not find a way to handle this with php.

+4
source share
2 answers

The DOM uses libxml under it. LibXML should be able to use Directory files when they are placed in /etc/xml/catalog . Same way on windows IIRC.

Feel free to raise your function request to make the path customizable with PHP:

+4
source

The problem you are facing is that PHP cannot solve the following way:

 urn:oasis:names:tc:dita:xsd:highlightDomain.xsd:1.2 

in your system.

You can replace instances of such URIs with what PHP can resolve.

One thing that comes to my mind is registering a stream wrapper that automatically resolves these URIs for you.

As an alternative, you can read the XSD files yourself and convert them to DATA URIs , and then replace the old urn: URI with the new data URI. Code example:

  $name = 'file.xsd'; $path = '/path-to-file/'.$name; $data = file_get_contents($path); $file = 'data://text/plain;base64,'.base64_encode($data); 

Hope this helps.

+2
source

All Articles