How to use PHP to access and manipulate the DOM (1) _php tutorial

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

 
 
  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's 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's 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 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 ...

  • 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.