if statement - php - do something on soap empty response or not found -


i need search on ws, have working, need able know when soap can not find word i'm looking.

for example, when search ke-5977 response , data

<getchoferesresult xmlns:a="http://schemas.datacontract.org/2004/07/asdf.dto" xmlns:i="http://www.w3.org/2001/xmlschema-instance">    <a:choferes>       <a:choferesdto>          <a:dc_patente>ke-5977</a:dc_patente>          <a:dc_patente_habitual>ke-5977</a:dc_patente_habitual>          <a:dc_rut_chofer>10165014-6</a:dc_rut_chofer>          <a:dc_tipo_equipo>4</a:dc_tipo_equipo>          <a:dc_tipo_transportista>e</a:dc_tipo_transportista>          <a:dg_nombre_chofer>juan soto</a:dg_nombre_chofer>          <a:dg_tipo_de_equipo>camiĆ³n</a:dg_tipo_de_equipo>          <a:dg_tipo_transportista>externo (se llama transporte ocasionalmente)</a:dg_tipo_transportista>          <a:dn_ano_fabricacion>1988</a:dn_ano_fabricacion>          <a:dq_capacidad_equipo>30.0000</a:dq_capacidad_equipo>       </a:choferesdto>    </a:choferes> </getchoferesresult> 

but if put wrong "ke-7759" nothing.

<getchoferesresult xmlns:a="http://schemas.datacontract.org/2004/07/asdf.dto" xmlns:i="http://www.w3.org/2001/xmlschema-instance">             <a:choferes/>          </getchoferesresult>       </getchoferesresponse>    </s:body> </s:envelope> 

i need show message "code not found" when empty response soap (soap request did not found code).

please me.

update:

this taken soapui: http://i.stack.imgur.com/oy4lc.jpg

in php this:

i ask if $isarray array because response soap can have multiple responses, values when multiple responses have ask "$response->getchoferesresult->choferes->choferesdto", if 1 response, values in "$response->getchoferesresult->choferes".

$response = $sclient->getchoferes(array("req"=>array("patentehabitual"=>$patente)));       $isarray = $response->getchoferesresult->choferes->choferesdto;     $xml = $response->getchoferesresult->choferes;     if (is_array($isarray)){         foreach($xml $chofer){              foreach($chofer $chofer2){                 $rut=$chofer2->dc_rut_chofer;                 $nombre=$chofer2->dg_nombre_chofer;                 ?><option value="<?php echo strtoupper($rut); ?>"     selected="selected"><?php echo strtoupper($nombre); ?></option><?php               }          }     }else{         foreach($xml $chofer){             if($chofer->dc_patente && $chofer->dg_nombre_chofer && $chofer->dc_patente_habitual){                 $rut=$chofer->dc_rut_chofer;                 $nombre=$chofer->dg_nombre_chofer;                  ?><option value="<?php echo strtoupper($rut); ?>" selected="selected"><?php echo strtoupper($nombre); ?></option><?php               }else{                 ?><option value="" selected="selected">patente no encontrada</option><?php              }         }     } 

also, know if can order responses value, in case dg_nombre_chofer (by name).

thanks.

you can use strpos($response, '<a:choferes/>') http://php.net/strpos

i use simplexml , convert object array using:

    function objectsintoarray($arrobjdata, $arrskipindices = array()){     $arrdata = array();      // if input object, convert array     if (is_object($arrobjdata)) {         $arrobjdata = get_object_vars($arrobjdata);     }      if (is_array($arrobjdata)) {         foreach ($arrobjdata $index => $value) {             if (is_object($value) || is_array($value)) {                 $value = objectsintoarray($value, $arrskipindices); // recursive call             }             if (in_array($index, $arrskipindices)) {                 continue;             }             $arrdata[$index] = $value;         }     }     return $arrdata; }      $process = $response->retrievelistingdataresult;     $process = utf8_encode($process);     $xml = '<?xml version="1.0" encoding="utf-8"?>'.$process;     $xmlobj = simplexml_load_string($xml);     $arrxml = objectsintoarray($xmlobj); 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -