3.1 AttributeList

The AttributeList interface allows access to an element’s attribute specifications.

The SAX parser implements this interface and passes an instance to the SAX application as the second argument of each startElement event.

The instance provided returns valid results only during the scope of the startElement invocation. To save it for future use, the application must make a copy; the AttributeListImpl helper class provides a convenient constructor for making a copy.

An AttributeList includes only attributes that have been specified or have default values; #IMPLIED attributes will not be included.

There are two ways for the SAX application to obtain information from the AttributeList. First, it can iterate through the entire list. The following code sample illustrates this:

 
 SAXException * startElement (const unicode * name, AttributeList * atts) { 
 for (int i = 0; i < atts->getLength(); i++) { 
 const unicode * name = atts->getName(i); 
 const unicode * type = atts->getType(i); 
 const unicode * value = atts->getValue(i); 
 [...] 
 } 
 } 
 
 

The result of the getLength method will be zero if there are no attributes.

As an alternative, the application can request the value or type of specific attributes. The following code illustrates this method.

 
 SAXException * startElement (const unicode * name, AttributeList * atts) { 
 const unicode * identifier = atts->getValue(L"id"); 
 const unicode * label = atts->getValue(L"label"); 
 [...] 
 } 
 
 

DirXML provides an implementation of AttributeList via the C++ class AttributeListImpl.