How to use XML DOM in PHP

In this article I am going to explain about XML DOM.
  • 2064


The XML DOM (Document Object Model ) is used for accessing and manipulating XML documents. In it XML elements can be created and added as node objects to the XML tree structure.

There are two basic type of XMl parser:

  • Tree-based parser

    The tree based parser is used to load the entire XML document into memory and provides access to the tree element. e.g, Document object model (DOM).
  • Event based parser

    Event based parser is used when a specific event occurs, it call a function to handle it.

Example of XML DOM

To load XML file with XML DOM ,follow the fallowing steps:

First create an XML file:

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





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


After it, create a PHP application for loading an XML file:

$xmlDoc = new DOMDocument();

print $xmlDoc->saveXML();


xml dom php.jpg

You may also want to read these related articles :

Ask Your Question 

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

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.