|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-11-17 09:48 UTC] a dot testa at wifisolution dot it
Description: ------------ php fails to validate a xml against a xsd. the xml is build with the DOM interface. the function schemaValidate returns true if i load the document from a file but not with the same document created on the fly. as workaround i can create the document, write it on a file, load againt and then validate. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 23:00:01 2025 UTC |
here sample code that can reproduce the problem class DOMDocument_NIC extends DOMDocument{ public function isValid_onfile(){ $tempFile = time() . '-' . rand() . '-xmlvalidation.tmp'; $this->save($tempFile); // Create temporary DOMDocument_NIC and re-load content from file. $tempDom = new DOMDocument(); $tempDom->load($tempFile); // Delete temporary file. if (is_file($tempFile)){ unlink($tempFile); } return $tempDom->schemaValidate('hosting_epp_nic_it/epp-1.0.xsd'); } public function isValid_onfly(){ return $this->schemaValidate('hosting_epp_nic_it/epp-1.0.xsd'); } } $doc = new DOMDocument_NIC('1.0', 'UTF-8'); $doc->xmlStandalone='no'; $xml_epp = $doc->createElementNS("urn:ietf:params:xml:ns:epp-1.0",'epp'); $doc->appendChild($xml_epp); $xml_epp->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xml_epp->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance' ,'xsi:schemaLocation', 'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd'); $xml_command = $doc->createElement('command'); $xml_epp->appendChild($xml_command); $xml_login = $doc->createElement('logout'); $xml_command->appendChild($xml_login); $xml_cltrid = $doc->createElement('clTRID',"123456"); $xml_command->appendChild($xml_cltrid); //$response = new DOMDocument_NIC(); //$response->loadXML($xml); echo htmlentities($doc->saveXML())."<br />"; echo "Valido on File: ".$doc->isValid_onfile(); echo "Valido on Fly: ".$doc->isValid_onfly();