Back to Contents


The DomDocument class

Summary:

See also: Built-in Classes, XML Utils


Basics

Purpose:

The DomDocument class provides methods to manipulate a data tree, following the DOM standards.

Syntax:

om.DomDocument

Methods:

Class Methods
Name Description
create( tag STRING )
 
RETURNING om.DomDocument
Creates a new, empty DomDocument object, where tag identifies the tag name of the root element.
createFromXmlFile( file STRING )
 
RETURNING om.DomDocument
Creates a new DomDocument object using an XML file specified by the parameter file. Returns NULL if an error occurs.
Object Methods
Name Description
copy( src om.DomNode, deep INTEGER )
 
RETURNING om.DomNode
Clones a DomNode (with child nodes if deep is TRUE).
createChars( text STRING )
 
RETURNING om.DomNode
Creates a DomNode as a text node.
createElement( tag STRING )
 
RETURNING om.DomNode
Creates a new empty DomNode object with a tag name specified by tag
getDocumentElement( )
 
RETURNING om.DomNode
Returns the root node of the DOM document.
getElementById( id INTEGER )
 
RETURNING om.DomNode
An internal integer identifier is automatically assigned to each DomNode object. With this method, you get an element by its id.
removeElement( e om.DomNode ) Removes a DomNode object and any descendent DomNodes from the document.

Usage:

A DomDocument object holds a DOM tree of DomNode objects.

A unique root DomNode object is owned by a DomDocument object.

You can get the root node with the DomDocument.getDocumentElement() method.

You can get a specific node by its internal identifier with the DomDocument.getElementById() method.

New nodes can be created with the DomDocument.createElement() method, and inserted in the DOM tree with the DomNode.insertbefore() method.

New text nodes can be created with the DomDocument.createChars() method, and inserted in the DOM tree with the DomNode.insertbefore() method.

Once you have the root element, you can recursively manipulate child nodes with the DomNode class methods.

Warnings:

  1. To create an instance of the DomDocument class, you must declare a variable with the type om.DomDocument, and use a method like DomDocument.create() to instantiate the object.

Examples

Example 1:

01 MAIN
02   DEFINE d om.DomDocument
03   DEFINE r om.DomNode
04   LET d = om.DomDocument.create("MyDocument")
05   LET r = d.getDocumentElement()
06 END MAIN