Let's talk about how to use PHP to access and operate DOM (1 ). The DOM tree defines the logical structure of documents and methods for controlling your access to and operations on these documents. With DOM, developers can create XML or HTML documents, operate on their results, add and modify the DOM tree to define the logical structure of the document, and control your access to and operations on these documents. With DOM, developers can create XML or HTML documents, operate on their results, and add, modify, and delete document elements and content. DOM can be accessed from any programming language. This article uses the PHP 5 DOM extension, which is part of the PHP core. Therefore, you do not need to install other software except PHP.
DOM tree nodes follow the XML naming rules, such:
1. Document node -- indicates the DOMDocument interface
2. Element node -- indicates the DOMElement interface
3. Attribute node -- indicates the DOMAttr interface
4. Comment node -- indicates the DOMComment interface
5. Text node -- indicates the DOMText interface
Extract element
This section describes how to extract elements and values from the DOM tree. this document uses Book. xml as an example to describe its content, as shown in listing 1.
Listing 1 Book. xml
- xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <book>
-
- <name>XML Processing I name>
- <author>John Smith Jr. author>
- <publisher>HisOwnTM publisher>
- <ISBN>111-222-333-4441 ISBN>
- <contents>
- <chapter_I>
- <title>What is XML about ? title>
- <content>XML (Extensible Markup Language) is a ... content>
- chapter_I>
- <chapter_II>
- <title>SAX title>
- <content>SAX is a simple API for ... content>
- chapter_II>
- <chapter_III>
- <title>StAX title>
- <content>Much powerful and flexible, StAX, is very... content>
- chapter_III>
- <chapter_IV>
- <title>DOM
- <subtitle>DOM concept
- <continut>Starting to use DOM... continut>
- subtitle>
- <subchapter_IV_I>
- <title>First DOM application... title>
- < content > Here it is your first DOM application... content>
- subchapter_IV_I>
- title>
- chapter_IV>
- <end>The end... end>
- contents>
-
- book>
First download the PHP code compressed package used in this article,
Bytes. With DOM, developers can create XML or HTML documents, operate on their results, and add and repair...