0
votes

I created an XML file but when I tried to validate against XSD I keep geting the following error:

Error 1845: Element '{http://www.stormware.cz/schema/version_2/data.xsd}dataPack': No matching global declaration available for the validation root.

PHP 5.4.7 libxml 2.7.8.

My function:

public function validateXml($dokument){
    // Enable user error handling
    libxml_use_internal_errors(true);

    $xml = new DOMDocument();
    $xml->load($dokument);
    $tempFile = time() . '-' . rand() . '-document.tmp';
    $xml->save($tempFile);

    $tempDom = new DOMDocument();
    $tempDom->load($tempFile);

    // Delete temporary file.
    if (is_file($tempFile))
    {
        unlink($tempFile);
    }



    if (!$tempDom->schemaValidate('order.xsd')) {
        print '<b>DOMDocument::schemaValidate() Generated Errors!</b>';
        $this->libxml_display_errors();
    }
}

My XSD file: www.stormware.cz/schema/version_2/data.xsd

My XML file:

 <?xml version="1.0" encoding="Windows-1250"?> 
<dat:dataPack id="ob001" ico="12345678" application="StwTest" version = "2.0" note="Import Objednávky" 
xmlns:dat="http://www.stormware.cz/schema/version_2/data.xsd" 
xmlns:ord="http://www.stormware.cz/schema/version_2/order.xsd" 
xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd" >


<dat:dataPackItem id="OBJ001" version="2.0">


<ord:order version="2.0"> 
<!--prijata objednavka s polozkama--> 
<ord:orderHeader> 
<ord:orderType>receivedOrder</ord:orderType> 
<ord:numberOrder>20140505A001</ord:numberOrder> 
<ord:date>2014-10-14</ord:date> 
<ord:dateFrom>2014-10-14</ord:dateFrom> 
<ord:dateTo>2014-10-14</ord:dateTo> 
<ord:text>Objednáváme u Vás zboží dle ústní dohody</ord:text> 
<ord:partnerIdentity> 
<typ:address> 
<typ:company>Otma a.s.</typ:company> 
<typ:division>Obchodní oddělení</typ:division> 
<typ:name>Petr Novák</typ:name> 
<typ:city>Brno</typ:city> 
<typ:street>Nová 15</typ:street> 
<typ:zip>61900</typ:zip> 
<typ:ico>789456</typ:ico> 
<typ:dic>CZ789456</typ:dic> 
</typ:address> 
</ord:partnerIdentity> 
<ord:paymentType> 
<typ:ids>hotově</typ:ids> 
</ord:paymentType> 
<ord:priceLevel> 
<typ:ids>Sleva 1</typ:ids> 
</ord:priceLevel> 
</ord:orderHeader>


<ord:orderDetail> 
<!--textova polozka--> 
<ord:orderItem> 
<ord:text>Sestava PC</ord:text> 
<ord:quantity>1</ord:quantity> 
<ord:delivered>0</ord:delivered> 
<ord:rateVAT>high</ord:rateVAT> 
<ord:homeCurrency> 
<typ:unitPrice>200</typ:unitPrice> 
</ord:homeCurrency> 
</ord:orderItem>


<!--skladova polozka--> 
<ord:orderItem> 
<ord:quantity>1</ord:quantity> 
<ord:delivered>0</ord:delivered> 
<ord:rateVAT>high</ord:rateVAT> 
<ord:homeCurrency> 
<typ:unitPrice>198</typ:unitPrice> 
</ord:homeCurrency> 
<ord:stockItem> 
<typ:stockItem> 
<typ:ids>STM</typ:ids> 
</typ:stockItem> 
</ord:stockItem> 
</ord:orderItem> 
</ord:orderDetail>



<ord:orderSummary> 
<ord:roundingDocument>math2one</ord:roundingDocument> 
</ord:orderSummary>


</ord:order>


</dat:dataPackItem>


</dat:dataPack>
1

1 Answers

0
votes

If your schema is the one rooted in the schema document at www.stormware.cz/schema/version_2/data.xsd, then why are you validating using the expression $tempDom->schemaValidate('order.xsd')?

If (as it appears to an outsider) the 'order.xsd' you are pointing to is http://www.stormware.cz/schema/version_2/order.xsd (or a copy of it), then your code is not pointing to what you say is your schema document, but to a different schema document, which describes a schema in which the element {http://www.stormware.cz/schema/version_2/data.xsd}dataPack is not declared. (This is what the error message is telling you.)

If you want a schema validator to validate your input against the declaration of the dataPack element, you have to ensure that the schema contains a declaration for that element.

(Your two comments make no sense to me.

You say that pointing to 'order.xsd' is "according to specification". What does that mean? If you are supposed to be writing something valid against the schema rooted in .../order.xsd, why are you using an element which is not declared in that schema (and why to you say that your schema is at http://www.stormware.cz/schema/version_2/data.xsd? That's not the same schema at all, as any glance at the relevant documents would establish.

You also say that pointing to a particular location in your file system leads to an error message complaining that the file at that location is not a schema document. The resource at http://www.stormware.cz/schema/version_2/data.xsd is a schema document; an obvious guess would be that you either got the file location path wrong, or that you are supposed to have a copy of all the relevant schema documents in appropriate locations relative to each other, and you don't.)

In any case, the short answer to your apparent question ("what is going wrong?") is that you are not succeeding in pointing to the schema you say you are intending to use. Fix that and your error message will go away.