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 :
[ 0 ] Comments