Skip to content
Advertisement

convert string to xml in PHP

When I use simplexml_load_file from a webservice, it returns

JavaScript

But, I cannot parse it as XML to get the attributes. I need it to be formatted as such:

JavaScript

and then this code works:

JavaScript

I tried str_replace and decoding, without success.

Advertisement

Answer

The contents of the “string” element is an XML document itself – stored in an text node. You can consider it an envelope. So you have to load the outer XML document first and read the text content, then load it as an XML document again.

JavaScript

In DOM:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement