Summary:
See also: Built-in Classes, XML Utils
The DomDocument class provides methods to manipulate a data tree, following the DOM standards.
om.DomDocument
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. |
createFromString(
source STRING ) RETURNING om.DomDocument |
Creates a new DomDocument object by parsing the XML string passed as parameter. 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. |
createEntity( text STRING ) RETURNING om.DomNode |
Creates a DomNode as an entity 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 |
Gets an element using its id, the internal integer identifier automatically assigned to each DomNode object. |
removeElement( e om.DomNode ) |
Removes a DomNode object and any descendent DomNodes from the document. |
A unique root DomNode object is owned by a DomDocument object.
To create an instance of the DomDocument class, you must first declare a variable with the type om.DomDocument.
Then, use the method om.DomDocument.create()
to instantiate a new, empty
DomDocument object.
To create a document from an existing XML file, use the method om.DomDocument.createFromXmlFile()
.
You can also use the om.DomDocument.createFromString()
method to create a document from a string in memory.
New nodes can be created with the createElement()
method.
New text nodes can be created with the createChars()
method.
New entity nodes can be created with the createEntity()
method.
Clone a DomNode object using the copy()
method.
Once a new DomNode object is created, you can for example inserted it in the DOM tree
with the insertBefore()
method of a DomNode object
You can get the root node with the getDocumentElement()
method. Once you have the root element, you can recursively manipulate child nodes
with the DomNode class methods
You can get a specific node of the DomDocument by using its internal identifier with the
getElementById()
method.
Use the removeElement()
method to remove an Element from a DomDocument.
01
MAIN02
DEFINE d om.DomDocument03
DEFINE r om.DomNode04
LET d = om.DomDocument.create("MyDocument")05
LET r = d.getDocumentElement()06
END MAIN