tags:

views:

53

answers:

2

I am working with the XML file string below and I've tried a number of methods to try and get access to certain parts of the XML contents. Please see the code after the XML file below for my attempt:

<?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"&gt;
<soap:Body>
<Address_ListResponse xmlns="http://example.example.com/"&gt;
<Address_ListResult>
<Address>
<HoldingId xsi:nil="true"/>
<MainId>1617931</MainId>
<ContactId>8</ContactId>
<Description>Home, All Purposes</Description>
<Position/>
<Department/>
<Organisation/>
<AddressLabel>Mr Joe Bloggs</AddressLabel>
<AddressLine1>1 Fake Road</AddressLine1>
<AddressLine2/>
<AddressLine3/>
<Town>Faketown</Town>
<CountyId>818</CountyId>
<PostCode>FA33 4KE</PostCode>
<CountryId>3</CountryId>
<Phone>01234567890</Phone>
<EvePhone/>
<Mobile/>
<Email>[email protected]</Email>
<Fax/>
<WWW/>
<AddressTypeId>1</AddressTypeId>
<IsBilling>true</IsBilling>
<IsMailing>true</IsMailing>
<IsDelivery>true</IsDelivery>
<IsInherited>false</IsInherited>
<GridN/>
<GridE/>
<Latitude/>
<Longitude/>
<CensationCode/>
<IsDeleted>false</IsDeleted>
<HoldingPersonalDetailsId xsi:nil="true"/>
<IsSynced>false</IsSynced>
<BeenProcessed>false</BeenProcessed>
<CountyName/>
<CountryName/>
<AddressTypeName>Home</AddressTypeName>
</Address>
</Address_ListResult>
</Address_ListResponse>
</soap:Body>
</soap:Envelope>

Code for accessing the XML content:

$xml = simplexml_load_string($result);

echo "Town: " . $xml->children('http://schemas.xmlsoap.org/soap/envelope/')-&gt;children('http://example.example.com/')-&gt;Address_ListResponse-&gt;Town;

The above code was based on a link posted by another StackOverFlow question: http://blog.preinheimer.com/index.php?/archives/172-SimpleXML,-Namespaces-Hair-loss.html

Any help would be appreciated.

Thanks.

A: 

Consider using the SOAP extension instead.
See the example in the PHP Manual on how to write a client.

An alternative would be to use Zend_Soap as a standalone component.

Gordon
Those links seem to be all about using SOAP to get data. I've actually got the XML data and now want to manipulate it using PHP. I don't see how the SOAP extension would help me to do that?
baswoni
@baswoni A Soap Client can fetch data from a Soap Server. If you specifiy a class map when creating the Soap Client, you can map the returned data structures to your class. See the last four lines in the example.
Gordon
A: 

Turns out the answer I was looking for wasn't SimpleXML - or at least I couldn't get that to work.

What I have done is used the xml_parse_into_struct to create an array of values returned from the XML data: http://www.php.net/manual/en/function.xml-parse-into-struct.php

baswoni