Jump to content

php simplexml help


gnrmatt

Recommended Posts

Hi,

 

I'm trying to get to grips with basic PHP SimpleXml so please accept my apologise if i'm doing something blatently stupid here.

 

I have an XML Feed as follows:

 

<tour>
<tourName>Amazon Riverboat Adventure</tourName>
<dossierCode>PVIIA</dossierCode>
<url>http://www.gapadventures.com/trips/amazon-riverboat-adventure/PVIIA/2011/</url>
<tripDescription>Hop aboard a riverboat and experience the Amazon in style. The cuisine onboard is regional and provides a unique—and delicious—window into local culture. Led by an Amazon Reserve Naturalist guide, your cruise will include daily excursions by motorized skiff designed to reveal the exotic wildlife that calls the rainforest home—with any luck you’ll spot sloths, toucans or pink dolphins! And, with two full days for exploration in Pacaya Samiria Reserve, you'll have the chance to experience the jungle up close. Gain a rare glimpse of how life ‘on the river‘ is lived and experience the magic of the Amazon on this once-in-a-lifetime riverboat adventure.</tripDescription>
<tripStyle>Classic</tripStyle>
</tour>

 

I want to get just the tour name from this so i have done:

 

<?php
// displays all the file nodes
if(!$xml=simplexml_load_file('xmlfeed.xml')){
    trigger_error('Error reading XML file',E_USER_ERROR);
}
// displays first user's name
echo 'Displaying Tour Name... <br />';
echo $xml->$tour[0]->tourName;
?>

 

However this fails to display the tourname for me. I'm sure it's something really stupid that i'm doing but any help is greatly appreciated!

 

Many thanks!

 

Matt

Link to comment
Share on other sites

Sorry - Resolved myself. For reference:

 

<?php
if(!$xml=simplexml_load_file('http://bookedy:bookED19@www.gapadventures.com/api/feeds/tours/PVIIA/')){
    trigger_error('Error reading XML file',E_USER_ERROR);
}
foreach ($xml->tourName as $tourname){
echo $tourname;
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.