Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Monday, 1 July 2013

Start with XML - fetch and display the xml datas using php


books.xml :   
<?xml version="1.0"?>
<datas>
  <books>
    <book>
      <id>1</id>       <title>PHP Undercover</title>         <author>Arun</author>     </book>     <book>       <id>2</id>       <title>PHP Enterprise</title>         <author>Vibin</author>     </book>   </books> </datas>

xmlread.php :
<?php
$xml = simplexml_load_file("books.xml")        or die("Error: Cannot create object");        //include the books.xml file foreach($xml as $books)                                       // seperate variables, books array from xml file { foreach($books as $book )                           // seperate variables, book array from books file       {  echo $book->id;                                        //display the id  echo "<br />";  echo $book->title;                                     //display the title  echo "<br />";  echo $book->author;                                //display the author  echo "<br />"; }
} ?>
Output:
1
PHP Undercover
Arun
2
PHP Enterprise
Vibin

Download

Thursday, 20 June 2013

Structure of xml

Input XML FILE:
<?xml version="1.0"?>
<note>
    <to cat="head">
        <cc>Arun</cc>
        <cc>Vibin</cc>
    </to>
    <from>
        <bc>Jani</bc>
        <bc>ishya</bc>
    </from>    
</note>


EXPLAIN:
<note>------->parent Element
<to>,<from>-->Child Element
<cc>,<bc>----->siblings
cat----------->attribute
Strcture Tree Diagram: