Chapter 3 DynaScript Predefined Objects


DOMDocument methods

The DOMDocument object inherits the methods from the DOMNode object, as well as the methods discussed in this section.

createAttribute method

Syntax

DOMDocument.createAttribute( name )

Description

Creates a DOMAttribute object representing an attribute of the given name.

The created attribute does not have any place in the document. It can be set on an element by using the setAttributeNode method of a DOMElement object, and the value of the attribute can be set using the setAttribute method of a DOMElement object.

name is the name of the attribute for which a DOMAttribute object is being created.

Return

A DOMAttribute object.

Example

This example creates an attribute named Region.

domDoc.createAttribute( "Region" );

See also

"DOMAttribute object".

"setAttribute method".

createCDATASection method

Syntax

DOMDocument.createCDATASection( data )

Description

Creates a CDATA node whose value is the specified string. data is the content of the CDATA section.

The created CDATA section does not have any place in the document. It can be added as the child of a node by using the appendChild method of a DOMNode object.

Return

A DOMCDATASection object.

Example

This example creates a CDATA section with text "Jane & John Doe", and adds it to the document as the last element before the end of the document element.

xmlString = "Jane & John Doe"
domCDATA = domDoc.createCDATASection( xmlString );
element.appendChild( domCDATA );

See also

"DOMCDATASection object".

"appendChild method".

createComment method

Syntax

DOMDocument.createComment( comment )

Description

Creates a DOMComment object representing a comment containing the specified string. comment should contain the text of the comment only, and should exclude the comment start (<!--) and end (-->) characters.

The DOMComment object can be added as the child of a node in the document using the DOMNode.appendChild method, or one of the other DOMNode methods.

Return

A DOMComment object.

Example

This example creates a comment on the document domDoc and adds it to the document as the final element before the end of the document element (docElem).

domComment = domDoc.createComment( 
"Browsers ignore this string" );
docElem.appendChild( domComment );

See also

"DOMComment object".

"DOMNode methods".

createDocumentFragment method

Syntax

DOMDocument.createDocumentFragment( )

Description

Creates an empty DOMDocumentFragment object. These fragments can be used in copy and paste operations.

Return

A document fragment

Example

To create a document fragment, enter:

domDoc.createDocumentFragment;

See also

"DOMDocumentFragment object".

"DOMNode methods".

createElement method

Syntax

DOMDocument.createElement( tagName )

Description

Creates a DOMElement object representing the specified element. tagName is the name of the element type that is to be instantiated. Tag names in XML are case-sensitive.

The element can be added as the child of a node using DOMNode.appendChild method, or one of the other DOMNode methods.

Return

A DOMElement object

Example

This example creates an element named Customer.

domDoc.createElement( "Customer" );

See also

"DOMElement object".

"DOMNode methods".

createEntityReference method

Syntax

DOMDocument.createEntityReference( name )

Description

Creates a DOMEntityReference object with the specified name.

Return

A DOMEntityReference object.

Example

This example creates a reference to the entity for the less than sign (left angle bracket).

domDoc.createEntityReference( "lt" );

See also

"DOMEntityReference object".

"DOMNode methods".

createProcessingInstruction method

Syntax

DOMDocument.createProcessingInstruction( target, data )

Description

Creates a DOMProcessingInstruction object given the specified target and data strings. The parameters are:

Return

A DOMProcessingInstruction object.

Example

This example creates a processing instruction that is a simple form of the required heading for an XML document. It then appends this processing instruction to an empty DOMDocument object.

domDoc = new DOMDocument();
docPI = domDoc.createProcessingInstruction( "xml", "version='1.0'" );
domDoc.appendChild( docPI );

See also

"DOMProcessingInstruction object".

"DOMNode methods".

createTextNode method

Syntax

DOMDocument.createTextNode( data )

Description

Creates a DOMText object representing the specified data string.

Return

A DOMText object.

Example

This example creates a text node with content "Bartlebooth".

domDoc.createTextNode( "Bartlebooth" )

See also

"DOMNode methods"

getElementsByTagName method

Syntax

DOMDocument.getElementsByTagName( tagname  )

Description

Returns a DOMNodeList object of all the DOMElement objects with a given tag name in the order in which they would be encountered in the document. Tag names in XML are case-sensitive. The special tag name "*" can be used to retrieve a list of all DOMElement objects regardless of the tag name.

To search for DOMElement objects that are children of a particular element, use the getElementsByTagName method on the DOMElement object.

Return

A DOMNodeList object containing all the matched objects.

Example

This example gets all elements named Region from the document domDoc, and loops over those elements.

elemList = domDoc.getElementsByTagName( "Region" );
for( iElem=0; iElem < elemList.length; iElem++ ){
elem = elemList.item( iElem );
-- operations here
}

prettyPrint method

Syntax

DOMDocument.prettyPrint()

Description

This method is not part of the DOM specification, and is provided for debugging purposes.

Return

A string containing a representation of the document structure.

Example

To print out the entire structure of a document named domDoc, enter:

document.writeln( domDoc.prettyPrint() );

 


Copyright © 1999 Sybase, Inc. All rights reserved.