Re: How to parse this kind of XML
| From: | Nathan Nobbe | Date: | Fri, 08 Feb 2008 00:12:17 +0000 |
| Subject: | Re: How to parse this kind of XML | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268921@lists.php.net to get a copy of this message | ||
On Feb 7, 2008 6:51 PM, Daniel Brown <parasane@gmail.com> wrote:
> I'm sure you're already aware of it, and that it's just a typo in
> the email, but there's a space between the lt carat and the
> event:sessionType node declaration.
>
that screwed me the last time i was posting on a simplexml
namespace issue; silly gmail :D
well, i know there is like nothing that really describes the 3rd and 4th
parameters
on the SimpleXMLElement constructor; or the 2 methods on the
SimpleXMLElement::children() method either, in the manual online.
however, since i just learned about phpt yesterday :), i was able to find a
unit test
distributed w/ php that actually tests said parameters for the
SimpleXMLElement
constructor.
php-5.2.5/ext/simplexml/tests/profile13.phpt
in there youll find this test xml;
$xml =<<<EOF
<?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 foo="bar">
<businessInfo businessKey="bla"/>
</businessList>
</soap:Body>
</soap:Envelope>
EOF;
and then the SimpleXMLElement is constructed via,
$sxe = simplexml_load_string($xml, NULL, 0, 'soap', 1);
removing the namespace declarations in the test xml caused the
test to fail.
you could just str_replace() the first element of the response and
drop a fake namespace in there; its dirty, but it would let you still
use SimpleXML...
-nathan