Monday 21, May 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    About Us    |    Contact Us

  Reading xml file using php

The easiest way to read a well-formed XML file is to use the Document Object Model (DOM) library compiled into some installations of PHP. The DOM library reads the entire XML document into memory and represents it as a tree of nodes. Here is a script which reads the xml file.
Cut & Paste Script
Books.xml

 <books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>Jack Herrington</author>
<title>Podcasting Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</books>

PHP code to read Books.xml

<?php
  $doc = new DOMDocument();
  $doc->load( 'Books.xml' );
 
  $books = $doc->getElementsByTagName( "book" );
  foreach( $books as $book )
  {
  $authors = $book->getElementsByTagName( "author" );
  $author = $authors->item(0)->nodeValue;
 
  $publishers = $book->getElementsByTagName( "publisher" );
  $publisher = $publishers->item(0)->nodeValue;
 
  $titles = $book->getElementsByTagName( "title" );
  $title = $titles->item(0)->nodeValue;
 
  echo "$title - $author - $publisher<br><br>";
  }
  ?>
 
   
     RELATED SCRIPTS
 
Comparing two arrays using php
This code example will take two arrays and compares 2nd array with 1st. It will show the list of elements which are not found in the first array....more »
Category : PHP Examples Hits : 649
   
Email validation using regular expression php
Here is a php script to validate email address. We are using regular expression for validation....more »
Category : PHP Examples Hits : 1010
   
Reversing a string using php
This code example will reverse the given string using php....more »
Category : PHP Examples Hits : 715
   
Difference Between two dates using php
This function will return the number of days elapsed between two dates....more »
Category : PHP Examples Hits : 559
   
creating new table in MySql using php
Here is an example to create a new table in mysql database....more »
Category : PHP Examples Hits : 656
   
   
SCRIPT CATEGORIES
 
  C Programs
C Programs scripts
  C++ Programs
C++ Programs scripts
  Java Programs
Java Programs scripts
  JavaScript Examples
JavaScript Examples scripts
  PHP Examples
PHP Examples scripts
  VBScript Examples
VBScript Examples scripts
 
 
 
POPULAR E-BOOKS
 
Download Friggin  Idiot s Guide to Buying and Selling on eBay  Ebook Friggin Idiot s Guide to Buying and Selling on eBay
   
Download Back to Basics Making the Most of Affiliate Marketing  Ebook Back to Basics Making the Most of Affiliate Marketing
   
Download Data Structures and Algorithms with Object-Oriented Design Patterns in C++  Ebook Data Structures and Algorithms with Object-Oriented Design Patterns in C++
   
Download How to Receive Goods FOR FREE Ebook How to Receive Goods FOR FREE
   
Download Passions to Profits Ebook Passions to Profits
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz