How to use XML DOM in PHP
In this article I am going to explain about XML DOM.
PHP XML DOM
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"?>
<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 loading an XML file:
<html>
<body>
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("test.xml");
print $xmlDoc->saveXML();
?>
</body>
</html>
|
Output:
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