php - Reading specific xml data using SimpleXMLElement -


i have challenges reading value of "cmbdestinosv" , each of "chk_xxxxx" in "coberdata" using simplexmlelement in below code snippet. code snippet xml response.

i have tried $xml->coberdata->chk_c0000; $xml->riskdata->cmbdestinosv->option->cd[1]; nothing returned. please help.

<root>    <riskdata label="risk details">      <cmbdestinosv afectaalprecio="true" dataname="cmbdestinosv" id="cmbdestinosv" name="cmbdestinosv" type="5" style="width:120" label="destination" visible="true" maxlength="2" readonly="false" obligatorio="true" size="3" newline="false" etiquetaencima="false" value="-1">-1       <option>         <cd>-1</cd>         <ds/>       </option>         <option>         <cd>7</cd>         <ds>05 - wordlwide excluding usa &amp; canada - wordlwide excluding usa &amp; canada</ds>       </option>         <option>         <cd>10</cd>         <ds>08 - worldwide - countries</ds>       </option>      </cmbdestinosv>   </riskdata>     <coberdata label="coverage details">      <chk_c0000 afectaalprecio="true" dataname="chk_c0000" id="chk_c0000" name="chk_c0000" type="6" label="bagages" visible="true" onclick="" maxlength="180" readonly="false" obligatorio="false" size="180" newline="false" etiquetaencima="false" value="0"/>       <chk_i0000 afectaalprecio="true" dataname="chk_i0000" id="chk_i0000" name="chk_i0000" type="6" label="medical complementary services" visible="true" onclick="" maxlength="180" readonly="true" obligatorio="true" size="180" newline="false" etiquetaencima="false" value="1"/>       <chk_f0000 afectaalprecio="true" dataname="chk_f0000" id="chk_f0000" name="chk_f0000" type="6" label="personal accidents" visible="true" onclick="" maxlength="180" readonly="true" obligatorio="true" size="180" newline="false" etiquetaencima="false" value="1"/>       <chk_d0002 afectaalprecio="true" dataname="chk_d0002" id="chk_d0002" name="chk_d0002" type="6" label="travel delay" visible="true" onclick="" maxlength="180" readonly="true" obligatorio="true" size="180" newline="false" etiquetaencima="false" value="1"/>       <chk_g0000 afectaalprecio="true" dataname="chk_g0000" id="chk_g0000" name="chk_g0000" type="6" label="personal liability" visible="true" onclick="" maxlength="180" readonly="true" obligatorio="true" size="180" newline="false" etiquetaencima="false" value="1"/>       <chk_b0003 afectaalprecio="true" dataname="chk_b0003" id="chk_b0003" name="chk_b0003" type="6" label="personal assistance" visible="true" onclick="" maxlength="180" readonly="true" obligatorio="true" size="180" newline="false" etiquetaencima="false" value="1"/>       <chk_can afectaalprecio="true" dataname="chk_can" id="chk_can" name="chk_can" type="6" label="cancellation" visible="true" onclick="" maxlength="180" readonly="false" obligatorio="false" size="180" newline="false" etiquetaencima="false" value="0"/>       <chk_u0030 afectaalprecio="true" dataname="chk_u0030" id="chk_u0030" name="chk_u0030" type="6" label="accidental damage" visible="true" onclick="" maxlength="180" readonly="true" obligatorio="true" size="180" newline="false" etiquetaencima="false" value="1"/>    </coberdata>  </root> 

your code worked fine retrieve target element, prints inner text of element, empty. if call asxml() instead, print correct element :

echo $xml->coberdata->chk_c0000->asxml(); 

if meant access 1 of attributes instead, try way :

echo $xml->coberdata->chk_c0000->attributes()->afectaalprecio; 

eval.in demo

output :

<chk_c0000 afectaalprecio="true" dataname="chk_c0000" id="chk_c0000" name="chk_c0000" type="6" label="bagages" visible="true" onclick="" maxlength="180" readonly="false" obligatorio="false" size="180" newline="false" etiquetaencima="false" value="0"/>  true 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -