BigBrotherBot v1.8.0
System Development Information for the BigBrotherBot project.

b3::lib::elementtree::ElementTree::ElementTree Class Reference

ElementTree wrapper class. More...

List of all members.

Public Member Functions

def __init__
def getroot
 Gets the root element for this tree.
def parse
 Loads an external XML document into this element tree.
def getiterator
 Creates a tree iterator for the root element.
def find
 Finds the first toplevel element with given tag.
def findtext
 Finds the element text for the first toplevel element with given tag.
def findall
 Finds all toplevel elements with the given tag.
def write
 Writes the element tree to a file, as XML.

Private Member Functions

def _setroot
 Replaces the root element for this tree.
def _write

Private Attributes

 _root

Detailed Description

ElementTree wrapper class.

This class represents an entire element hierarchy, and adds some extra support for serialization to and from standard XML.

Parameters:
elementOptional root element. file Optional file handle or name. If given, the tree is initialized with the contents of this XML file.

Constructor & Destructor Documentation

def b3::lib::elementtree::ElementTree::ElementTree::__init__ (   self,
  element = None,
  file = None 
)

Member Function Documentation

def b3::lib::elementtree::ElementTree::ElementTree::_setroot (   self,
  element 
) [private]

Replaces the root element for this tree.

This discards the current contents of the tree, and replaces it with the given element. Use with care.

Parameters:
elementAn element instance.
def b3::lib::elementtree::ElementTree::ElementTree::_write (   self,
  file,
  node,
  encoding,
  namespaces 
) [private]
def b3::lib::elementtree::ElementTree::ElementTree::find (   self,
  path 
)

Finds the first toplevel element with given tag.

Same as getroot().find(path).

Parameters:
pathWhat element to look for.
Returns:
The first matching element, or None if no element was found. Element or None
def b3::lib::elementtree::ElementTree::ElementTree::findall (   self,
  path 
)

Finds all toplevel elements with the given tag.

Same as getroot().findall(path).

Parameters:
pathWhat element to look for.
Returns:
A list or iterator containing all matching elements, in document order. list of Element instances
def b3::lib::elementtree::ElementTree::ElementTree::findtext (   self,
  path,
  default = None 
)

Finds the element text for the first toplevel element with given tag.

Same as getroot().findtext(path).

Parameters:
pathWhat toplevel element to look for.
defaultWhat to return if the element was not found.
Returns:
The text content of the first matching element, or the default value no element was found. Note that if the element has is found, but has no text content, this method returns an empty string. string
def b3::lib::elementtree::ElementTree::ElementTree::getiterator (   self,
  tag = None 
)

Creates a tree iterator for the root element.

The iterator loops over all elements in this tree, in document order.

Parameters:
tagWhat tags to look for (default is to return all elements)
Returns:
An iterator. iterator
def b3::lib::elementtree::ElementTree::ElementTree::getroot (   self)

Gets the root element for this tree.

Returns:
An element instance. Element
def b3::lib::elementtree::ElementTree::ElementTree::parse (   self,
  source,
  parser = None 
)

Loads an external XML document into this element tree.

Parameters:
sourceA file name or file object.
parserAn optional parser instance. If not given, the standard XMLTreeBuilder parser is used.
Returns:
The document root element. Element
def b3::lib::elementtree::ElementTree::ElementTree::write (   self,
  file,
  encoding = "us-ascii" 
)

Writes the element tree to a file, as XML.

Parameters:
fileA file name, or a file object opened for writing.
encodingOptional output encoding (default is US-ASCII).

Member Data Documentation


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Properties