eval.in

Paste #11844

PHP — PHP 5.4.6, pasted 1 year ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
/**
 * Getting data from Soap response stdclass object in PHP
 * @link http://stackoverflow.com/a/15239365/367456
 */

$result_GetAlladdressResult_any = <<<BUFFER
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
  <NewDataSet xmlns="">
    <Table diffgr:id="Table1" msdata:rowOrder="0">
      <AdressID>643</AdressID><CustomerID>36</CustomerID><LocationID>176</LocationID><StreetName>asdf</StreetName><HouseNo>1234</HouseNo><AlternatePhone>5632256</AlternatePhone><LandMark>asdf </LandMark><MainLocID>2</MainLocID><locName>ANDOLANA CIRCLE</locName><MainLoc>Mysore    </MainLoc>
    </Table>
  </NewDataSet>
</diffgr:diffgram>
BUFFER;

$xml = new SimpleXMLElement($result_GetAlladdressResult_any);

# traversal
$table = $xml->NewDataSet->Table[0];
echo $table->LocationID, "\n", $table->MainLoc, "\n";

# xpath
echo $xml->xpath('//LocationID')[0], "\n", $xml->xpath('//MainLoc')[0], "\n";

Program Output

176
Mysore    
176
Mysore    

OK (0.008 sec real, 0.011 sec wall, 13 MB, 51 syscalls)

Fork