PHP XMLLesson 75Free preview
PHP DOM Parser
This lesson is part of PHP · All levels
Summary
DOM treats XML as a node tree through the DOMDocument class, so we can read and edit the structure at the same time. You load the document with load() or loadXML(), then search for the element using getElementsByTagName(). To add or delete data, createElement, appendChild, and removeChild are available, and the results are saved via save() or saveXML().
Key points
- The DOMDocument represents the entire document as a node tree.
- It's reading from the file, from the string.
- GetElementsByTagName() collects elements by name, complete with item(0).
- CreateElement and appendChild are used to add nodes, save() write results to the file.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.