Friday, April 11, 2008

simple xml


The XML file we'll use looks something like this:



   <?xml version="1.0" encoding="utf-8" ?>

   <movies>

      <movie>
         <title>Star Wars</title>

         <year>1977</year>

      </movie>

      <movie>

         <name>Apocalypse Now</name>

         <year>1979</year>

      </movie>

      <movie>

         <title>Raiders Of The Lost Ark</title>

         <year>1981</year>

      </movie>

   </movies>

if (!$myxml=simplexml_load_file('mymovies.xml')){

echo 'Error reading the XML file';

}

foreach($myxml as $movie){

echo 'Title: ' . $movie->title . '<br />';

echo 'Year: ' . $movie->year . '<br /><hr />';

}

?>

No comments:

Post a Comment