-2

I have a URL from where i am trying to get data value and display in a table. Its a single data , no loop.

I use file_get_contents php function

<?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 &amp; 9:54PM</PICKUP_DATE>
    <ORDER_NO>2341</ORDER_NO>
    <CURRENT_STATUS>DELIVERED</CURRENT_STATUS>
    <TRACKING_CODE>T002</TRACKING_CODE>
  </Consignment>
</ArrayOfConsignment>

Now i want to catch each data field like Pickup date , Order No etc and display in a table .

Can anyone help me on this ??

Also can i use this using CURL ? Please share the code if you have .

Thanks a lot for your help

Lorry.B
  • 45
  • 1
  • 5

2 Answers2

0
$xml=simplexml_load_file("yourxmlfile.xml") or die("Error: Cannot create object");
echo $xml->Consignment[0]->DOCKNO. "<br>";
echo $xml->Consignment[1]->DOCKNO; 

you can get the tag value by this method

Ahmet ATAK
  • 342
  • 2
  • 13
  • I just tried your code , Its not working gives the following error Warning: simplexml_load_file(): I/O warning : failed to load external entity "yourxmlfile.xml" in C:\xampp\htdocs\delcart\test.php on line 5 Error: Cannot create object – Lorry.B Apr 28 '15 at 07:19
  • i will edit the code again – Ahmet ATAK Apr 28 '15 at 07:20
0

You may follow the below code to get it done.

<?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 &amp; 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'];
?> 
  • Not working , gives me a blank page..... What i am doing is getting the URL value in php and store into a variable like this ................................................ $content = file_get_contents('http://www.domain.com/cust_ws_ver2.asmx/TrackConsignment_Header_New?userName=XXX&password=YYY&clientId=Delex&DOCNO=A000001');..........And from the variable $content i want to get the each value like Docket no, Date etc etc – Lorry.B Apr 28 '15 at 07:27
  • remove the "coment line" to echo"
    ";print_r($dataArray); it will print.Also echo the variable so it will print.Since there is not echo statement ,it is not printing.
    – Pravat Kumar Sahoo Apr 28 '15 at 07:28
  • Got it Working , i see echo is not there .... Thanks , BTW is there anyway to do it in CURL as the URL i am using for file_gets_content have few variables . Thanks a Lot for your help – Lorry.B Apr 28 '15 at 07:29
  • Change the Line from //echo"
    ";print_r($dataArray); to echo"
    ";print_r($dataArray);
    – Pravat Kumar Sahoo Apr 28 '15 at 07:31
  • Means you want to get the xml through CuRl and parse it in your server and work on the Data.Ryt? – Pravat Kumar Sahoo Apr 28 '15 at 07:33
  • yes , I already did voteup .. Thanks – Lorry.B Apr 28 '15 at 07:58
  • But it is not showing in my Answer.Any way if you will find time please do that.Thanks in Advance. – Pravat Kumar Sahoo Apr 28 '15 at 10:52