What is loop in XML DOM through PHP

In this article I am going to explain about loop in XML DOM.
  • 2804

Looping through XML DOM in PHP

XML is a data storage format. An XMl file describes the structure of the data. You can read xml file with loop, for it you can intilize the XML parser , load the XML, and loop through all elements of the  <note> element.

Example of looping through XML

To load XML file ,follow the fallowing steps:

First create an XML file:

<?xml version="1.0" encoding="ISONO"?>

<note>

  <to>Mcn_Solution</to>

  <from>Dinesh</from>

  <heading>Singhr</heading>

  <body>Don't forget me this weekend!</body>

</note>


After it, create a PHP application for reading  an XML file through loop:
 

<html>

<body>

<?php

$xmlDoc = new DOMDocument();

$xmlDoc->load("test.xml");

 

$x = $xmlDoc->documentElement;

foreach ($x->childNodes AS $item)

  {

  print $item->nodeName . " = " . $item->nodeValue . "<br />";

  }

?>

</body>

</html>


Output:

loopxml dom php.jpg

You may also want to read these related articles :
here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.