php - Read SOAP XML file -


i've soap xml file (data.xml) contains below data, in fact response of api:

<?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">         <soap:body>             <getauctionlist2response xmlns="gdauctionsbiddingwsapi">                 <getauctionlist2result>                     <auctionlist isvalid="true" totalrecords="98">                         <auction id="112910726" name="software-server.org" traffic="2" bidcount="0" price="$9 usd" valuationprice="-" timeleft="9h 36m " rowid="1"/>                         <auction id="112926015" name="softwarelawsuits.com" traffic="0" bidcount="0" price="$8 usd" valuationprice="-" timeleft="9h 39m " rowid="2"/>                         <auction id="113234131" name="softwarecraftory.com" traffic="4" bidcount="0" price="$11 usd" valuationprice="-" timeleft="9h 53m " rowid="3"/>                         <auction id="112906125" name="softwaresystems.co" traffic="0" bidcount="0" price="$8 usd" valuationprice="-" timeleft="10h 15m " rowid="4"/>                         <auction id="112692380" name="softwarerepair.org" traffic="0" bidcount="0" price="$5 usd" valuationprice="-" timeleft="10h 46m " rowid="5"/>                     </auctionlist>                 </getauctionlist2result>             </getauctionlist2response>         </soap:body>     </soap:envelope> 

when try read it, not work , throws error. first try:

$doc = new domdocument(); $doc->load( 'data.xml' );  $auctionlist = $doc->getelementsbytagname( "auctionlist" );  foreach( $auctionlist $list ) {   $names = $list->getelementsbytagname( "auction" );   echo "<b>$name\n</b><br>"; } 

error:

notice: domdocument::load(): xmlns: uri gdauctionsbiddingwsapi not absolute in file:///c:/xampp/htdocs/adam_auction/data.xml, line: 4 in c:\xampp\htdocs\adam_auction\readfile.php on line 5  notice: undefined variable: name in c:\xampp\htdocs\adam_auction\readfile.php on line 13 

second try:

$s = simplexml_load_string('http://localhost/adam_auction/data.xml'); print_r($s); 

error:

warning: simplexml_load_string(): entity: line 1: parser error : start tag expected, '<' not found in c:\xampp\htdocs\adam_auction\readfile.php on line 4  warning: simplexml_load_string(): http://localhost/adam_auction/data.xml in c:\xampp\htdocs\adam_auction\readfile.php on line 4  warning: simplexml_load_string(): ^ in c:\xampp\htdocs\adam_auction\readfile.php on line 4 

can me wrong soap xml file?

1) xml file invalid? 2) how read , save variable? 3) how 'auction' tag information , save array?

written in bad style solves problem. remove soap envelope's basic tags, load xml , print '@'.

$response   =   file_get_contents($file_path); $response   =   explode(php_eol, $response);  $skip   =   array(0, 1, 2, count($response)-1, count($response)-2); $xml    =   array();  for($i=0;$i<count($response);$i++){     if(!in_array($i, $skip)){         $xml[]  =   $response[$i];     } }  $xml    =   implode('', $xml);  @print_r(simplexml_load_string($xml)); // or @$obj  =  simplexml_load_string($xml); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -