Back to Contents


The SaxAttributes class

Summary:

See also: Classes and Objects, XML Utilities


Syntax

The SaxAttributes class provides methods to manipulate XML element attributes for a SAX driver.

Syntax:

om.SaxAttributes


Methods:

Class Methods
Name Description
copy( src SaxAttributes )
  RETURNING om.SaxAttributes
Clones an existing SaxAttributes object.
create()
  RETURNING om.SaxAttributes
Creates a new, empty SaxAttributes object.
Object Methods
Name Description
addAttribute( n STRING, v STRING ) Adds an attribute to the end of the list.
clear() Clears the attribute list.
getLength()
  RETURNING INTEGER
Returns the number of attributes in the list.
getName( pos INTEGER )
  RETURNING STRING
Returns the name of the attribute at position pos.
getValue( att STRING )
  RETURNING STRING
Returns the value of the attribute identified by the name att.
getValuebyIndex( pos INTEGER )
  RETURNING STRING
Returns the value of the attribute at position pos.
removeAttribute( pos INTEGER )
  RETURNING INTEGER
Removes the attribute at position pos.
setAttributes( atts om.SaxAttributes ) Clears the current attribute list and adds all attributes of atts

Usage:

This class provides basic methods to manipulate attributes when processing a SAX filter. The SaxAttributes object is a list containing the attributes of the element.

Creating a SaxAttributes object

To process element attributes, a SaxAttributes object can be used in cooperation with an XmlReader object. You get an instance of SaxAttributes with the getAttributes() method. 

The following SaxAttributes Class methods are also provided:

The om.SaxAttributes.create() method creates a new, empty SaxAttributes object. 

The om.SaxAttributes.copy() method clones an existing SaxAttributes object. 

Returning the value of an attribute

The getValue() method returns the value of the attribute specified by name.

The getValueByIndex() method returns the value of the attribute at the specified position. 

Returning the number of attributes

The getLength() method returns the number of attributes in the list.

Returning the name of an attribute

The getName() method returns the name of the attribute at the specified position in the list.

Adding attributes

The addAttribute() method adds a new attribute to the end of the attributes list. 

Removing attributes

The clear() method clears the attributes list.

The removeAttribute() method removes the attributes at the given position in the list.

Replacing the attributes list

The setAttributes() method clears the current list and adds all the attributes of the specified SaxAttributes object.


Examples

Example 1:

01 FUNCTION displayAttributes( a )
02    DEFINE a om.SaxAttributes
03    DEFINE i INTEGER
04    FOR i=1 to a.getLength()
05       DISPLAY a.getName(i) || "=[" || a.getValueByIndex(i) || "]"
06    END FOR
07 END FUNCTION