Looping through XML

Looping through XML


Posted in : PHP Posted on : January 21, 2011 at 5:42 PM Comments : [ 0 ]

This section contains the detail about the Looping through XML using PHP.

Looping through XML

In this section, you will learn how to loop through all the elements of the root node of an XML document.

The XML file & PHP file used in this example is given below :

demo.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<phonebook>
<name>Ankit</name>
<surname>Kaushal</surname>
<mobile>99999999</mobile>
<location>New Delhi</location>
</phonebook>

LoopingXml.php

<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("XML/demo.xml");

$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item)
{
print $item->nodeName . " = " . $item->nodeValue . "<br />";
}
?>

Output :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics