note 94709 modified in simplexmlelement.construct by danbrown
| From: | danbrown@php.net | Date: | Thu, 19 Nov 2009 18:19:06 +0000 |
| Subject: | note 94709 modified in simplexmlelement.construct by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163096@lists.php.net to get a copy of this message | ||
SimpleXML does not correctly parse SOAP XML results if the result comes back with colons
â:â in a tag, like <soap:Envelope>. Why? Because SimpleXML treats the colon
character â:â as an XML namespace, and places the entire contents of the SOAP XML result
inside a namespace within the SimpleXML object. There is no real way to correct this using
SimpleXML, but we can alter the raw XML result a little before we send it to SimpleXML to parse.
All we have to do is use the preg_replace function to get rid of the colons in the SOAP response
tags BEFORE you hand it off to SimpleXML, like so:
<?php
// SimpleXML seems to have problems with the colon ":" in the <xxx:yyy> response
tags, so take them out
$xmlString = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3",
$response);
?>
--was--
SimpleXML does not correctly parse SOAP XML results if the result comes back with colons
â:â in a tag, like <soap:Envelope>. Why? Because SimpleXML treats the colon
character â:â as an XML namespace, and places the entire contents of the SOAP XML result
inside a namespace within the SimpleXML object. There is no real way to correct this using
SimpleXML, but we can alter the raw XML result a little before we send it to SimpleXML to parse.
All we have to do is use the preg_replace function to get rid of the colons in the SOAP response
tags BEFORE you hand it off to SimpleXML, like so:
// SimpleXML seems to have problems with the colon ":" in the <xxx:yyy> response
tags, so take them out
$xmlString = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3",
$response);
http://php.net/manual/en/simplexmlelement.construct.php