使用URL php中的属性提取XML数据

使用URL php中的属性提取XML数据,php,xml,curl,simplexml,Php,Xml,Curl,Simplexml,我有一个url,它是一个XML数据响应 像这样 <Account account="ihs" timezone="GMT+05:30"> <Description>The Indian Heights School</Description> <Device id="09647"> <Description>DL1PD0228</Description> <EventData device="09647"> &l

我有一个url,它是一个XML数据响应 像这样

<Account account="ihs" timezone="GMT+05:30">
<Description>The Indian Heights School</Description>
<Device id="09647">
<Description>DL1PD0228</Description>
<EventData device="09647">
<Timestamp epoch="1416968997">2014/11/26 07:59:57 GMT+05:30</Timestamp>
<StatusCode code="0xF401">Ignition_On</StatusCode>
<GPSPoint>28.56262,77.05264</GPSPoint>
<Speed units="km/h">0.0</Speed>
<Odometer units="Km">4390.1</Odometer>
<Geozone index="0">tihs</Geozone>
<Address>The Indian Heights School</Address>
</EventData>
</Device>
<Device id="8786">
<Description>DL1VC1750</Description>
<EventData device="8786">
<Timestamp epoch="1416989072">2014/11/26 13:34:32 GMT+05:30</Timestamp>
<StatusCode code="0xF020">Location</StatusCode>
<GPSPoint>28.56234,77.05284</GPSPoint>
<Speed units="km/h">0.0</Speed>
<Odometer units="Km">6154.6</Odometer>
<Geozone index="0">tihs</Geozone>
<Address>The Indian Heights School</Address>
</EventData>
</Device>
我很高兴

     SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [account] => ihs
            [timezone] => GMT+05:30
        )

    [Description] => SimpleXMLElement Object
        (
        )

    [Device] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => 09647
                        )

                    [Description] => SimpleXMLElement Object
                        (
                        )

                    [EventData] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [device] => 09647
                                )

                            [Timestamp] => 2014/11/26 07:59:57 GMT+05:30
                            [StatusCode] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [code] => 0xF401
                                        )

                                )

                            [GPSPoint] => 28.56262,77.05264
                            [Speed] => 0.0
                            [Odometer] => 4390.1
                            [Geozone] => tihs
                            [Address] => SimpleXMLElement Object
                                (
                                )

                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => 8786
                        )

                    [Description] => SimpleXMLElement Object
                        (
                        )

                    [EventData] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [device] => 8786
                                )

                            [Timestamp] => 2014/11/26 14:45:33 GMT+05:30
                            [StatusCode] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [code] => 0xF113
                                        )

                                )

                            [GPSPoint] => 28.61029,76.98159
                            [Speed] => 0.0
                            [Odometer] => 6155.0
                        )

                )

在描述前面,我没有任何东西,不知道如何提取它

您需要区分大小写:

echo $xml->Description;
也是一个foreach:

foreach($xml->device as $device) {
    echo $device->Description;
}

我得到了设备说明,但卡在了帐户->说明确保区分大小写。我在回答中忘记了这一点,但现在做了更改:)
foreach($xml->device as $device) {
    echo $device->Description;
}