Convert XML response to array in PHP -


I'm getting XML from an API request and want to know that only & lt; Soap: How to turn on the body & gt; to by

Any information that tells me in the right direction will be great!

Thanks in advance. / P>

Sample XML:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Soap: envelope xmlns: soap = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: wsa = "http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns: wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns: wsu = "http: //docs.oasis-open.org. wss / 2004/01 / oasis-200401-wss-wssecurity- utility.1.0.xsd "xmlns: xsd =" http://www.w3.org/2001/XMLSchema "xmlns: xsi =" http: // www. w3.org/2001/XMLSchema-instance"> & Lt; Soap: Header & gt; & Lt; Wsa: Action & gt; Http: //www.urlhere.com/< / wsa: Action & gt; & Lt; Wsa: MessageId & gt; Ubud: 00000000-0000-0000-0000-000000000000 & lt; / wsa: MessageId> & Lt; Wsa: RelatesTo & gt; Ubud: 00000000-0000-0000-0000-000000000000 & lt; / wsa: RelatesTo & gt; & Lt; Wsa: & gt; Http: //schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous< / wsa: & gt; & Lt; wsse: Security & gt; & Lt; Wsu: timestamp YSU: id = "timestamp-4cf61b60-957a-454a-a828-90bd373301af" & gt; & Lt; WSU: Created & gt; 2001-01-01T00: 00: 00Z & lt; / WSU: Created & gt; & Lt; WSU: Expired & gt; 2001-01-01T00: 00: 00Z & lt; / WSU: Expired & gt; & Lt; / WSU: Timestamp & gt; & Lt; / Wsse: Security & gt; & Lt; / Soap: Header & gt; & Lt; Soaps: Body & gt; & Lt; blah xmlns = "http://www.urlhere.com/schema" & gt; & Lt; Blahblah & gt; & Lt; Blahblahblah & gt; 0 & lt; / blahblahblah & gt; & Lt; / blahblah & gt; & Lt; / Blah & gt; & Lt; / Soap: Body & gt; & Lt; / Soap: Envelope & gt;   

I would like it as a result

  array ('body' = & gt; array ('blah' = & gt; array (' Blahblah '= & gt; array (' blahblahblah '= & gt; 0)))    

If you were used to use SimpleXML

You can prepare xpath to match on the namespace.

  $ simple = simplexml_load_string ($ xml); $ Result = $ simple-> Xpath ('// soap: body'); The result of echo $ [0] - & gt; Bah- & gt; Blah-block- & gt; Blahblablaah; I am not presenting the "array" solution because complex XML structures require different types of processing / repetition, which are covered by all simple XML documents.  

Addition: Adding a Good Example of Namespace Consumption

  $ simple = simplexml_load_string ($ xml); $ Simple & gt; RegisterXPathNamespace ('foo', 'http: //www.urlhere.com/schema'); $ Result = $ simple-> Xpath ('// foo: blah'); Result to return [0] - & gt; Blah-Blah- & gt; Blahblablaah;    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -