php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50201 Error validating xml with namespace against xsd
Submitted: 2009-11-17 09:48 UTC Modified: 2009-11-17 21:54 UTC
From: a dot testa at wifisolution dot it Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.11 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: a dot testa at wifisolution dot it
New email:
PHP Version: OS:

 

 [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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-17 10:11 UTC] rrichards@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2009-11-17 11:30 UTC] a dot testa at wifisolution dot it
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();
 [2009-11-17 21:54 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

createElement is level 1 non-namespace aware method. Use level 2 
createElementNS method for all elements and create them in the 
urn:ietf:params:xml:ns:epp-1.0 namespace.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 20 22:00:01 2025 UTC