4

I am trying to convert a SOAP response to XML.

SOAP has an envelop and a body

<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>

When I try to convert

$responseXML = simplexml_load_string($string);

I get

object(SimpleXMLElement)#20 (0) { } 

If I edit the $string as soap:Envelope and soap:Body I can get the XML.

What's wrong with :? Can not get XML.

I hope it's clear. Anyone?

bluish
  • 26,356
  • 27
  • 122
  • 180
ntan
  • 2,195
  • 7
  • 35
  • 56

2 Answers2

9

A SOAP message is already XML. The problem is that it has namespaces so you have to access it differently. (The part before the colon is the identifier for the namespace.)

Here (google cached copy) is an example of using namespaces with SimpleXML.
Here is a specific example for reading SOAP messages.

Community
  • 1
  • 1
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
1

SimpleXML requires special treatment for namespaced XML (ref.)

Dormilich
  • 927
  • 5
  • 11
  • Totally clear.But what about if i want to access for example xml->soap:Envelop->soap:Body->item1->item2 – ntan May 05 '10 at 13:26
  • because "soap:" is not tied to a namespace in this example. mind that not the namespace prefix must match, but the namespace itself. – Dormilich May 05 '10 at 13:53