Jump to content

XML parse issue


rfeio

Recommended Posts

Hi,

 

I have the following XML:

 

<NewDataSet>
  <TransactionList>
    <TransactionID>272201222</TransactionID>
    <TransactionDate>2008-12-31T11:05:00+00:00</TransactionDate>
    <SaleValue>3.3900</SaleValue>
  </TransactionList>
  <TransactionList>
    <TransactionID>274879519</TransactionID>
    <TransactionDate>2009-01-13T14:40:00+00:00</TransactionDate>
    <SaleValue>19.9900</SaleValue>
  </TransactionList>
</NewDataSet>

 

I would now like to create an array with this info. For that I have come up with the following code:

 

$count = count($xml -> TransactionList);

echo '<br><br>Total records = '.$count;

for($i=0; $i < $count; $i++)
{
   $transaction_id[$i]  = $xml -> TransactionList -> TransactionID;
   $transaction_date[$i] = $xml -> TransactionList -> TransactionDate;
   $sale[$i] = $xml -> TransactionList -> SaleValue;
}

 

 

The problem is that the array always gets the data from the first record. When I print the array I get:

 

Total records = 2

 

Record #1:

 

Transaction id= 272201222

Transaction date= 2008-12-31T11:05:00+00:00

Sale= 3.3900

 

Record #2:

 

Transaction id= 272201222

Transaction date= 2008-12-31T11:05:00+00:00

Sale= 3.3900

 

 

What am I missing? How can I load all the records on the XML to the array?

 

Cheers!

 

 

Link to comment
https://forums.phpfreaks.com/topic/140794-xml-parse-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.