PHP Beginner's Introduction to XML and DOM
1.What is DOM
W3C DOM provides a standard set of objects for HTML and XML documents, as well as standards for accessing and manipulating these documents interface.
W3C DOM is divided into different parts (Core, XML and HTML) and different levels (DOM Level 1/2/3):
* Core DOM - A standard set of objects that defines a standard for any structured document
* XML DOM -The Object Collection of the Standard of the XML Document
* HTML DOM -is the Object Collection of the HTML Document Definition Standard
# If you need to read and update-create and process-a XML document, you need XML parser.There are two basic XML parser types:
· Tree -based parser: This parser converts the XML document into a tree structure. It analyzes the entire document and provides access to elements in the tree, such as the Document Object Model (DOM). · Time-based parser: Treat XML documents as a series of events. When a specific event occurs, the parser calls a function to handle it. The DOM parser is a tree-based parser Look at the xml document fragment belowLevel 2: Root element:
Example:
First we create an xml file head.xml with the following codeThen we create a php file with the following codeTove Jani Reminder Don't forget me this weekend!
load("head.xml"); print $xmlDoc->saveXML(); ?>
How to traverse xml
Create a xml file first, for Head.xmland then create a PHP file.Tove Jani Reminder Don't forget me this weekend!