Below is a sample of how you can display XML on your website using PHP.

    // Loading the XML file
    $xml = simplexml_load_file("books.xml");
    echo "<h2>".$xml->getName()."</h2><br />";
    foreach($xml->children() as $book)
        echo "BOOK : ".$book->attributes()->id."<br />";
        echo "Author : ".$book->author." <br />";
        echo "Title : ".$book->title." <br />";
        echo "Genre : ".$book->genre." <br />";
        echo "Price : ".$book->price." <br />";
        echo "Publish Date : ".$book->publish_date." <br />";
        echo "Description : ".$book->description." <br />";
        echo "<hr/>";


The Sample XML file is below

<?xml version="1.0"?>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <description>An in-depth look at creating applications
      with XML.</description>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <description>A former architect battles corporate zombies,
      an evil sorceress, and her own childhood to become queen
      of the world.</description>


Share This Via: