ID:               37035
 Updated by:       [EMAIL PROTECTED]
 Reported By:      mir at datanom dot net
-Status:           Open
+Status:           Closed
 Bug Type:         SimpleXML related
 Operating System: *
 PHP Version:      5.1.2
 Assigned To:      helly
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

You need $sxe->children($ns) / attributes($ns)

where either $ns is the URI of your namespace or NULL if you want to
access non namespaced children/attributes. SXE objects do not allow
changing the namespace by property or array access.

In HEAD we now have the ability to also access the root element with
specific namespace.


Previous Comments:
------------------------------------------------------------------------

[2006-04-12 13:06:20] mir at datanom dot net

Had a wild idea which seems to prove something noticeable.
Study the example below which works:

<?php
//    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"; 
//    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
//    xmlns:xsd="http://www.w3.org/2001/XMLSchema";
$xml = <<<_XML
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
<soap:Body> 
<businessList 
    generic="2.0" operator="ms.com" truncated="false" 
    xmlns="urn:uddi-org:api_v2"> 
<businessInfos> 
    <businessInfo businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997">
        <name xml:lang="en">Microsoft DRMS Dev</name> 
        <serviceInfos>
            <serviceInfo 
                serviceKey="6166f8b2-436d-4001-9f68-f37ff8b47ea3" 
                businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997">
                <name xml:lang="en">Certification</name>
            </serviceInfo> 
        </serviceInfos> 
    </businessInfo>
</businessInfos>
</businessList>
</soap:Body> 
</soap:Envelope>
_XML;

$document = simplexml_load_string($xml);
if (!$document)
    echo "Failed to parse document!\n";
else
    print_r($document);
?>

Apparently simplexml_load_string does not like namespace references in
an element if this same element is extended from that same namespace.

------------------------------------------------------------------------

[2006-04-12 12:57:00] mir at datanom dot net

Forgot to provide a simple example:

<?php
//    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"; 
//    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
//    xmlns:xsd="http://www.w3.org/2001/XMLSchema";
$xml = <<<_XML
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope>
<soap:Body> 
<businessList 
    generic="2.0" operator="ms.com" truncated="false" 
    xmlns="urn:uddi-org:api_v2"> 
<businessInfos> 
    <businessInfo businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997">
        <name xml:lang="en">Microsoft DRMS Dev</name> 
        <serviceInfos>
            <serviceInfo 
                serviceKey="6166f8b2-436d-4001-9f68-f37ff8b47ea3" 
                businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997">
                <name xml:lang="en">Certification</name>
            </serviceInfo> 
        </serviceInfos> 
    </businessInfo>
</businessInfos>
</businessList>
</soap:Body> 
</soap:Envelope>
_XML;

$document = simplexml_load_string($xml);
if (!$document)
    echo "Failed to parse document!\n";
else
    print_r($document);
?>

This example works. Adding the 3 uncommented namespace declarations to
the root element will make simplexml_load_string return false.

------------------------------------------------------------------------

[2006-04-10 23:13:13] mir at datanom dot net

Description:
------------
Given this xml document simplexml_load_string and simplexml_load_file
returns false

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
<soap:Body> 
<businessList 
        generic="2.0" operator="ms.com" truncated="false" 
        xmlns="urn:uddi-org:api_v2"> 
<businessInfos> 
<businessInfo           businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997">
<name xml:lang="en">Microsoft DRMS Dev</name> 
<serviceInfos>
<serviceInfo 
serviceKey="6166f8b2-436d-4001-9f68-f37ff8b47ea3" 
businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997">
<name xml:lang="en">Certification</name>
</serviceInfo> 
</serviceInfos> 
</businessInfo>
</businessInfos>
</businessList>
</soap:Body> 
</soap:Envelope>

If I erase namespace references from the root element a valid simpleXML
object is returned:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope>
<soap:Body> 
<businessList 
        generic="2.0" operator="ms.com" truncated="false" 
        xmlns="urn:uddi-org:api_v2"> 
<businessInfos> 
<businessInfo           businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997">
<name xml:lang="en">Microsoft DRMS Dev</name> 
<serviceInfos>
<serviceInfo 
serviceKey="6166f8b2-436d-4001-9f68-f37ff8b47ea3" 
businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997">
<name xml:lang="en">Certification</name>
</serviceInfo> 
</serviceInfos> 
</businessInfo>
</businessInfos>
</businessList>
</soap:Body> 
</soap:Envelope>

Reproduce code:
---------------
class xmlParser
{
        private $document;

        public function __construct($xml)
        {
        $this->document =                             
simplexml_load_string((string)$xml);
        if (!$this->document)
                throw new xmlParserException("The XML document is not 
well-formed:
\n" . $xml);
        }
}

Expected result:
----------------
A SimpleXML Object



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=37035&edit=1

Reply via email to