Hi List

I have taken the advice of a number of people on the list and am back trying to
write my XML parser using SimpleXML. I am having a problem and I believe the
problem is my lack of understanding of arrays and simpleXML in spite of much
google searching and manual reading. I would appreciate some help.

The piece of XML I am parsing is as follows. I am working with a small section
to see if I can get my head around it.


<?xml version="1.0" encoding="UTF-8"?>
<?ypsilon RNGSchema="fareResponse.rnc" type="compact"?>
<fareResponse cntTarifs="122" offset="0">
  <vcrSummary>
        <vcr minPrice="1667" maxPrice="1667" totalTarifs="1" 
currency="USD">AA</vcr>
        <vcr minPrice="1374" maxPrice="4704" totalTarifs="2" 
currency="USD">PR</vcr>
  </vcrSummary>
</fareResponse>

If I use the following

$file = "test.xml";

        
  $data = simplexml_load_file($file);
        
  foreach ($data->vcrSummary as $vcrSummary)
          {
                var_dump($vcrSummary); 
       }

Then I get

object(SimpleXMLElement)#5 (1) {
  ["vcr"]=>
  array(2) {
    [0]=>
    string(2) "AA"
    [1]=>
    string(2) "PR"
  }
}

Which is pretty much what I would expect as there are 2 vcr tags.

If I then use

$file = "test.xml";

        
        $data = simplexml_load_file($file);

        foreach($data as $vcrSummary)
        {
                $z = $vcrSummary->vcr;
                print "$z \n";
                
        
        }

I get 3 blank lines and then AA which is the first of the two vcr values. The
examples I am looking at suggest I should have gotten both of the vcr values.

Many of the examples I am looking at say to use echo instead of print, eg

echo $vcrSummary->vcr;

and that just gives me AA and not both values that I would expect.

Can anyone point me in the right direction here.

Regards,
Richard Luckhurst                      
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to