我有一个URL,我想从中获取数据值并显示在表格中。它是单个数据,没有循环。
我使用file_get_contents php函数
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfConsignment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Consignment>
<ERROR />
<DOCKNO>A0000001</DOCKNO>
<PICKUP_DATE>13 Apr 2015 & 9:54PM</PICKUP_DATE>
<ORDER_NO>2341</ORDER_NO>
<CURRENT_STATUS>DELIVERED</CURRENT_STATUS>
<TRACKING_CODE>T002</TRACKING_CODE>
</Consignment>
</ArrayOfConsignment>
现在我想抓住每个数据字段,如取件日期,订单号等,并显示在表格中。
任何人都可以帮我吗?
我也可以使用CURL吗?如果有,请分享代码。
非常感谢你的帮助
答案 0 :(得分:0)
$xml=simplexml_load_file("yourxmlfile.xml") or die("Error: Cannot create object");
echo $xml->Consignment[0]->DOCKNO. "<br>";
echo $xml->Consignment[1]->DOCKNO;
您可以通过此方法获取标记值
答案 1 :(得分:0)
您可以按照以下代码完成此操作。
<?php
$myXMLData =
'<?xml version="1.0" encoding="utf-8"?>
<ArrayOfConsignment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Consignment>
<ERROR />
<DOCKNO>A0000001</DOCKNO>
<PICKUP_DATE>13 Apr 2015 & 9:54PM</PICKUP_DATE>
<ORDER_NO>2341</ORDER_NO>
<CURRENT_STATUS>DELIVERED</CURRENT_STATUS>
<TRACKING_CODE>T002</TRACKING_CODE>
</Consignment>
</ArrayOfConsignment>';
$xml = (array)simplexml_load_string($myXMLData) or die("Error: Cannot create object");
$dataArray = (array)$xml['Consignment'];
//echo"<pre>";print_r($dataArray);
$DOCKNO = $dataArray['DOCKNO'];
$PICKUP_DATE = $dataArray['PICKUP_DATE'];
$ORDER_NO = $dataArray['ORDER_NO'];
$CURRENT_STATUS = $dataArray['CURRENT_STATUS'];
$TRACKING_CODE = $dataArray['TRACKING_CODE'];
?>