Space for google add

XML-“book.xml”


 Create an application that reads “book.xml” file into simple XML

object. Display attributes and elements (Hint:simple_xml_load_file()

function)


book.xml

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

<bookstore>

  <book category="COOKING">

    <title lang="en">Everyday Italian</title>

    <author>Giada De Laurentiis</author>

    <year>2005</year>

    <price>30.00</price>

  </book>

  <book category="CHILDREN">

    <title lang="en">Harry Potter</title>

    <author>J K. Rowling</author>

    <year>2005</year>

    <price>29.99</price>

  </book>

  <book category="WEB">

    <title lang="en-us">XQuery Kick Start</title>

    <author>James McGovern</author>

    <year>2003</year>

    <price>49.99</price>

  </book>

  <book category="WEB">

    <title lang="en-us">Learning XML</title>

    <author>Erik T. Ray</author>

    <year>2003</year>

    <price>39.95</price>

  </book>

</bookstore>



book.php

<?php

$xml=simplexml_load_file("book.xml") or die("Error: Cannot create object");

echo "<br>";

for($i=0;$i<4;$i++)

{

$a=$xml->book[$i]->attributes();

print_r ($a);

echo "<br>";

}

echo "<br><br>";


for($i=0;$i<4;$i++)

{

$a=$xml->book[$i]->children();

print_r ($a);

echo "<br>";

}

  $a=$xml->book[0]->parent();

echo "$a";

?>


Post a Comment

0 Comments