2
votes

As stated by the official PHP documentation:

DOMDocument::schemaValidate — Validates a document based on a schema. Only XML Schema 1.0 is supported.

That being said, I have an XML Schema 1.1 file that I need to validate my XML against. My search for a solution has turned out nothing so far and judging by the answers on similar questions, libxml seem to only support 1.0, so anything that uses libxml is probably not going to work in this case.

Edit: For extra information, the schema contains the following (which is only valid for XML 1.1 and not for 1.0):

  <xs:element name="placeholder_1">
    <xs:complexType>
      <xs:all>
        <xs:element maxOccurs="unbounded" minOccurs="0" name="placeholder_2" type="xs:string"/>
        <xs:element maxOccurs="unbounded" minOccurs="0" name="placeholder_3" type="xs:string"/>
        <xs:element maxOccurs="1" minOccurs="0" name="placehoder_4" type="xs:string"/>
        <xs:element maxOccurs="1" minOccurs="0" name="placeholder_5" type="xs:string"/>
      </xs:all>
    </xs:complexType>
  </xs:element>
1
You can try Saxon for php: saxonica.com/download/c.xmlYitzhak Khabinsky
Saxon appears to require a license. The software I'm developing must be open source and only use open source libraries.Hero Solutions
You can use Saxon Home Edition (HE) free of charge.Yitzhak Khabinsky
Also, Xerces is open source and free of charge: xerces.apache.org/xerces2-j/xml-schema.htmlYitzhak Khabinsky
Saxon-HE does not support XSD. As far as I'm aware, the only open source implementation of XSD 1.1 is Xerces (Java). So I'm afraid there aren't any easy solutions. Most open source developments in the XML space stalled for lack of volunteers at least 10 years ago.Michael Kay

1 Answers

0
votes

Can you try as said below and see if it is working?

Convert the schema file to string.

Can be done roughly as said below (may be better ways available)

$doc->load('schema.xsd');
$doc->save('schema.xml');
$xmlfile = file_get_contents('schema.xml');

And then use DOMDocument::schemaValidateSource which takes string as input.

https://www.php.net/manual/en/domdocument.schemavalidatesource.php

Validates a document based on a schema defined in the given string.