1 回答
TA贡献1824条经验 获得超6个赞
即使不是严格的错误,我认为最好有一个扫描数组而不是scan结构中的几个键。
$object = $xml->xpath("//object[@pk = '1' and @model = 'awb']")[0] ;
// get all the scan stages object
$scanObjects = $object->xpath(".//object[@model = 'scan_stages']");
$scans = array(); // store all the scans info
foreach($scanObjects as $scanObject){
$scan = array() ; // store the current scan info
// iterate on all "field" in the current scan stage
foreach($scanObject->xpath('field') as $field){
$key = (string)$field->xpath('@name')[0] ; // name of the field
$value = (string) $field ; // value of the field
$scan[ $key ] = $value ; // add the field to the current scan info
}
$scans[] = $scan ; // add the current scan to the scan list
}
echo json_encode($scans);
输出 :
[{
"updated_on":"17 March, 2019, 03:10 ",
"status":"In-transit",
"reason_code_number":"002",
"scan_status":"PICKUP",
"location_city":"AMSTERDAM",
"location_type":"Hub",
"city_name":"AMSTERDAM",
"Employee":"JOEL - O94383"
},{
"updated_on":"18 March, 2019, 22:22 ",
"status":"Bag scanned at Hub",
"reason_code":" - ",
"reason_code_number":"003",
"scan_status":"IN",
"location":"I1H",
"location_city":"AMSTERDAM",
"location_type":"Hub",
"city_name":"AMSTERDAM",
"Employee":"ELLEN - 49821"
}]
- 1 回答
- 0 关注
- 142 浏览
添加回答
举报