June 2000
Intermediate to advanced
556 pages
8h 45m
English
Attributes in the DOM are accessed from an element node by means of the attributes variable. Attributes are stored in a structure known as a NamedNodeMap. A NamedNodeMap is like a NodeList except that nodes in a NamedNodeMap can be retrieved, based on the value of their nodeName attribute.
In the following example, a DOM tree is traversed, and attribute names and values printed out by traversal of a NamedNodeMap.
CD-ROM reference=11006.txt
C>type dom4.py """ Printing attributes from a DOM tree """ from xml.dom import core from xml.dom.walker import Walker from xml.dom.sax_builder import SaxBuilder import string,sys from xml.sax import saxexts,saxlib p = saxexts.make_parser() dh = SaxBuilder() p.setDocumentHandler(dh) ...Read now
Unlock full access