2016-04-14 27 views
1

xml biçiminde çıktı alıyorum. Awb_number, order_id, actual_weight vb. Gibi her bir <field>name değerini almak istiyorum. Her ad değerini nasıl alabilirim?php içinde xml verilerden değerler alın

<ecomexpress-objects version="1.0"> 
    <object pk="1" model="awb"> 
    <field type="BigIntegerField" name="awb_number">700054480</field> 
    <field type="CharField" name="orderid">5012</field> 
    <field type="FloatField" name="actual_weight">0.5</field> 
    <field type="CharField" name="origin">DELHI-DSW</field> 
    <field type="CharField" name="destination">DELHI-DLN</field> 
    <field type="CharField" name="customer">Ecom Express Private Limited - 32012</field> 
    <field type="CharField" name="consignee">MUKESH KUMAR GUPTA</field> 
    <field type="CharField" name="pickupdate">11-Feb-2013</field> 
    <field type="CharField" name="status">Delivered/Closed</field> 
    <field type="CharField" name="reason_code"/> 
    <field type="CharField" name="reason_code_description"/> 
    <field type="CharField" name="reason_code_number">999</field> 
    <field type="CharField" name="receiver">mukesh 9999488339</field> 
    <field type="CharField" name="expected_date">12-Feb-2013</field> 
    <field type="CharField" name="last_update_date">05-Apr-2013</field> 
    <field type="CharField" name="delivery_date">2013-02-17 11:26:00</field> 
    <field type="CharField" name="ref_awb">None</field> 
    <field type="CharField" name="rts_shipment"/> 
    <field type="CharField" name="system_delivery_update">2013-02-17 11:26:00</field> 
    <field type="CharField" name="rts_system_delivery_status"/> 
    </object> 
</ecomexpress-objects> 

kod aşağıda denedi ama

$xml = new SimpleXMLElement($server_output); 
foreach($xml->object->field as $key =>$value) 
{ 
    //foreach($element as $key => $value) 
     echo($key .'-' .$value)."<br>"; 


} 

cevap

1

name bir düğüm değeri değil vb xml metin awb_number,order_id,actual_weight gibi gösteremez, bu bir düğüm niteliktir.

echo $value['name']; // Output for first field: awb_number 
echo $value;   // Output for first field: 700054480 
: değerini almak için, dizi sözdizimi kullanmak zorunda