PHP正在努力解析一些XML

时间:2016-02-10 23:05:52

标签: php arrays xml

我正在调用一些Web服务,然后从XML响应中提取数据。大多数都很好,但其中一个服务允许我执行一些SQL来检索其他数据,并且此响应的布局与其他响应的布局非常不同。我无法修改服务,所以只需知道如何获取数据;

The data I am getting back is as follows, from a

 Print_r;

stdClass对象([schema] => stdClass对象([element] => stdClass对象([complexType] => stdClass对象([choice] => stdClass对象([element] => stdClass对象([complexType] => stdClass对象([sequence] => stdClass对象([element] =>数组([0] => stdClass对象([simpleType] => stdClass对象([restriction] => ; stdClass对象([maxLength] =>)))[1] => [2] => stdClass对象([simpleType] => stdClass对象([restriction] => stdClass对象([maxLength] = >)))[3] => [4] => [5] => stdClass对象([simpleType] => stdClass对象([restriction] => stdClass对象([maxLength] => )))[6] => stdClass对象([simpleType] => stdClass对象([restriction] => stdClass对象([maxLength] =>)))[7] => [8] => ; stdClass对象([simpleType] => stdClass对象([restriction] => stdClass对象([maxLength] =>)))))))))))[diffgram] => st dClass对象([VTSData] => stdClass对象([Table] =>数组([0] => stdClass对象([PreferredFieldManagerID] => L005 [优先级] => 1 [AreaOfExpertiseID] => 1 [X] => 72958 [Y ] => 5225329 [区] => PO BOX 15 [代理] => FLS-AUTO-UPLOAD [条件] => 0 [EquipmentName] => 11/02/2016)[1] => stdClass对象([PreferredFieldManagerID] => L005 [优先级] => 1 [AreaOfExpertiseID] => 1 [X] => 72958 [Y] => 5225329 [区] =>邮箱15 [条件] => 0 [EquipmentName] => 11/02/2016)[2] => stdClass对象([PreferredFieldManagerID] => L005 [优先级] => 1 [AreaOfExpertiseID] => 1 [X] = > 72958 [Y] => 5225329 [区] =>邮箱15 [条件] => 0 [EquipmentName] => 11/02/2016)[3] => stdClass对象([PreferredFieldManagerID] => L005 [优先级] => 1 [AreaOfExpertiseID] => 1 [X] => 72958 [Y] => 5225329 [区] =>邮箱15 [条件] => 0 [设备名称] => 11/02/2016)))))

我需要的元素是[X],[Y],[AreaofExpertiseId]等...     试过

 echo($result -> AreaOfExpertiseID);
    echo($result -> X);
    echo($result -> Y);

etc ...哪种语法适用于我的其他结果XML ...

但是这些失败了

Undefined property: stdClass::$AreaOfExpertiseID in ...etc...

请有人帮忙吗?

菲尔

1 个答案:

答案 0 :(得分:0)

如果您显示的print_r$result的内容,则您需要的数据位于

$result->diffgram->VTSData->Table

这将是一个对象数组,您可以迭代并获得您正在寻找的内容。

$table = $result->diffgram->VTSData->Table;
foreach ($table as $item) {
    echo $item->AreaOfExpertiseID, $item->X, $item->Y;
    // or whatever you need to do with them
}