How to use PHP to access and operate DOM (1) _ PHP Tutorial

Source: Internet
Author: User
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

 
 
  1. xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2. <book>
  3. <name>XML Processing I name>
  4. <author>John Smith Jr. author>
  5. <publisher>HisOwnTM publisher>
  6. <ISBN>111-222-333-4441 ISBN>
  7. <contents>
  8. <chapter_I>
  9. <title>What is XML about ? title>
  10. <content>XML (Extensible Markup Language) is a ... content>
  11. chapter_I>
  12. <chapter_II>
  13. <title>SAX title>
  14. <content>SAX is a simple API for ... content>
  15. chapter_II>
  16. <chapter_III>
  17. <title>StAX title>
  18. <content>Much powerful and flexible, StAX, is very... content>
  19. chapter_III>
  20. <chapter_IV>
  21. <title>DOM
  22. <subtitle>DOM concept
  23. <continut>Starting to use DOM... continut>
  24. subtitle>
  25. <subchapter_IV_I>
  26. <title>First DOM application... title>
  27. < content > Here it is your first DOM application... content>
  28. subchapter_IV_I>
  29. title>
  30. chapter_IV>
  31. <end>The end... end>
  32. contents>
  33. 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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.