Package glue :: Package ligolw :: Module ligolw :: Class PartialLIGOLWContentHandler
[hide private]
[frames] | no frames]

Class PartialLIGOLWContentHandler

source code

xml.sax.handler.ContentHandler --+    
                                 |    
                        object --+    
                                 |    
              LIGOLWContentHandler --+
                                     |
                                    PartialLIGOLWContentHandler

LIGO LW content handler object that loads only those parts of the document matching some criteria. Useful, for example, when one wishes to read only a single table from a file.

Example:

>>> from glue.ligolw import utils as ligolw_utils
>>> def contenthandler(document):
...     return PartialLIGOLWContentHandler(document, lambda name, attrs: name == Table.tagName)
...
>>> xmldoc = ligolw_utils.load_filename("demo.xml", contenthandler = contenthandler)

This parses "demo.xml" and returns an XML tree containing only the Table elements and their children.

Instance Methods [hide private]
 
__init__(self, document, element_filter)
Only those elements for which element_filter(name, attrs) evaluates to True, and the children of those elements, will be loaded.
source code
 
characters(self, content)
Receive notification of character data.
source code
 
endElementNS(self, *args)
Signals the end of an element in namespace mode.
source code
 
startElementNS(self, uri_localname, qname, attrs)
Signals the start of an element in namespace mode.
source code

Inherited from LIGOLWContentHandler: startAdcData, startAdcInterval, startArray, startColumn, startComment, startDetector, startDim, startIGWDFrame, startLIGO_LW, startParam, startStream, startTable, startTime

Inherited from xml.sax.handler.ContentHandler: endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, document, element_filter)
(Constructor)

source code 

Only those elements for which element_filter(name, attrs) evaluates to True, and the children of those elements, will be loaded.

Overrides: object.__init__

characters(self, content)

source code 

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

Overrides: xml.sax.handler.ContentHandler.characters
(inherited documentation)

endElementNS(self, *args)

source code 

Signals the end of an element in namespace mode.

The name parameter contains the name of the element type, just as with the startElementNS event.

Overrides: xml.sax.handler.ContentHandler.endElementNS
(inherited documentation)

startElementNS(self, uri_localname, qname, attrs)

source code 

Signals the start of an element in namespace mode.

The name parameter contains the name of the element type as a (uri, localname) tuple, the qname parameter the raw XML 1.0 name used in the source document, and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.

The uri part of the name tuple is None for elements which have no namespace.

Overrides: xml.sax.handler.ContentHandler.startElementNS
(inherited documentation)