The DOM tree defines the logical structure of the document and the methods that govern how you access and manipulate the documents. Using the DOM, developers can create XML or HTML documents, manipulate their results, and add, modify, and delete document elements and content. The DOM can be accessed from any programming language, and this article uses the PHP 5 DOM extension, which is part of the PHP core, so there is no need to install additional software other than PHP.
The DOM tree nodes follow the XML naming conventions, such as:
1. Document node--Indicates DOMDocument interface
2. Element node--Indicates DomElement interface
3. Attribute node--Indicates Domattr interface
4. Comment node--Indicates Domcomment interface
5. Text node--Indicates Domtext interface
Extracting elements
This section describes how to extract elements and values from the DOM tree, which is illustrated in this article using Book.xml as an example, 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's 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's your first DOM application ... content>
- subchapter_iv_i >
- title >
- Chapter_iv >
- < End > The end ... End>
- contents>
-
- Book >
First, download the PHP code compression package used in this article,
http://www.bkjia.com/PHPjc/446612.html www.bkjia.com true http://www.bkjia.com/PHPjc/446612.html techarticle The DOM tree defines the logical structure of the document and the methods that govern how you access and manipulate the documents. Using the DOM, developers can create XML or HTML documents, manipulate their results, add, fix ...