| Bug #37035 | Fail to produce a SimpleXML Object with namespace in root element | ||||
|---|---|---|---|---|---|
| Submitted: | 10 Apr 2006 11:13pm UTC | Modified: | 14 Apr 2006 3:33pm UTC | ||
| From: | mir at datanom dot net | Assigned to: | helly | ||
| Status: | Closed | Category: | SimpleXML related | ||
| Version: | 5.1.2 | OS: | * | ||
[10 Apr 2006 11:13pm UTC] mir at datanom dot net
[12 Apr 2006 12:57pm UTC] 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.
[12 Apr 2006 1:06pm UTC] 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.
[14 Apr 2006 3:33pm UTC] helly@php.net
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.
