Friday, 14 December 2012

PHP - XML: Retrieving Node Values

PHP XML Tips - Part 3: Read node values use simplexml is very easy. Look at this sample:
01    <?php
02    $xml = simplexml_load_file("books.xml")
03           or die("Error: Cannot create object");
04           
05    foreach($xml->children() as $books){
06        foreach($books->children() as $book => $data){
07          echo $data->id;
08          echo $data->title;
09          echo $data->author;
10          echo "<br />";
11        }
12    }
13   
14    ?>

You can write books.xml like in this post.

No comments:

Post a Comment