Package TEES :: Package Utils :: Module ElementTreeUtils
[hide private]

Module ElementTreeUtils

source code


Functions for easier use of cElementTree.

  Program:    cElementTree Utilities
  Date:       Oct. 16, 2007
  Author:     Jari Bjoerne

  Description: Convenience functions for easier use of cElementTree.


Version: $Revision: 1.20 $

Classes [hide private]
  ETWriter
Functions [hide private]
 
removeAll(element) source code
 
iterparse(file, elementName, callback, limit=-1)
Parse iteratively xml-files
source code
 
indent(elem, level=0)
indent-function as defined in cElementTree-documentation
source code
 
ETFromObj(obj)
obj can be 1) a string that ends with .xml -> the file is parsed and the resulting ElementTree returned 2) a string that ends with .xml.gz -> the file is unzipped, parsed, and the resulting ElementTree is returned 3) an open input stream -> the input is parsed and the resulting ElementTree is returned 4) an ElementTree or an Element -> obj is returned as-is, nothing is done
source code
 
ETIteratorFromObj(obj, events=None, parser=None)
obj can be 1) a string that ends with .xml -> the file is parsed and the resulting ElementTree returned 2) a string that ends with .xml.gz -> the file is unzipped, parsed, and the resulting ElementTree is returned 3) an open input stream -> the input is parsed and the resulting ElementTree is returned 4) an ElementTree or an Element -> obj is returned as-is, nothing is done
source code
 
write(rootElement, filename) source code
 
encodeNewlines(filename) source code
 
makePath(element, tagList) source code
 
toStr(element, recursive=True, removePreTag=True) source code
 
getElementByAttrib(parent, tag, attDict) source code
 
setDefaultElement(parent, name) source code
Variables [hide private]
  __package__ = 'TEES.Utils'
Function Details [hide private]

iterparse(file, elementName, callback, limit=-1)

source code 
Parse iteratively xml-files

This function offers a simple way to use the cElementTree
iterparse-function the way it is often used.

Keyword arguments:
file -- (file) file or file-like object to parse 
elementName -- (string) matching elements are passed to the callback
callback -- (function) called when parser has parsed an element
            of name elementName
limit -- (int) stop after reading "limit" elements. If -1, read
         until end of file. This is mostly useful when debugging
         programs that parse large files.

indent(elem, level=0)

source code 

indent-function as defined in cElementTree-documentation

This function will become part of cElementTree in some future release. Until then, it can be used from here. This function indents the xml-tree, so that it is more readable when written out.

Keyword arguments: elem -- (Element) root of the tree to indent level -- (int) starting level of indentation