PHP, DOM and XML : Part 1 – Introduction

In the document object model (DOM), a document is represented as a tree broken down into nodes (branches). The entire document is loaded in memory while using DOM. The primary data type in document object model is a Node, and all other node types are derived futher.The following are the node types in the DOM:

Attr: Attribute node
CDATASection: CDATA section node
Comment: Comment node
DocumentFragment: Document fragment node 181
Document: Document node
DocumentType: Document type node
Element: Element node
Entity: Entity node
EntityReference: Entity reference node
Notation: Notation node
ProcessingInstruction: PI node
Text: Text node

Each node type corresponds to a DOM object. Other objects such as NodeList, NameNodeMap, DOMImplementation, DOMException, and CharacterData exist which donot inherit from the node object. The document tree can be traversed in different directions. All nodes can be accessed, and the functionality available depends upon the type of node. Document and entity reference nodes are two types of nodes that have no value.

The following is a simple XML document:

1
2
3
4
5
<?xml version="1.0" ?>
<main>
<sub att1="Att1 value">sub Contents</sub>
<!-- This is a comment -->
</main>

By default, Whitespaces, line feeds and tabs are also included in the DOM tree as text nodes.

Share Article/Example:
  • Facebook
  • Twitter
  • del.icio.us
  • Digg
  • DotNetKicks
  • DZone