Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Private Attributes
xml.etree.ElementTree.TreeBuilder Class Reference

Generic element structure builder. More...

List of all members.

Public Member Functions

def __init__
def close
 Flushes the builder buffers, and returns the toplevel document element.
def data
 Adds text to the current element.
def start
 Opens a new element.
def end
 Closes the current element.

Private Member Functions

def _flush

Private Attributes

 _data
 _elem
 _last
 _tail
 _factory

Detailed Description

Generic element structure builder.

This builder converts a sequence of TreeBuilder.start, TreeBuilder.data, and h1>TreeBuilder.endmethodcallstoawell-formedelementstructure.</h1><p>YoucanusethisclasstobuildanelementstructureusingacustomXMLparser,oraparserforsomeotherXML-likeformat.@paramelement_factoryOptionalelementfactory.ThisfactoryiscalledtocreatenewElementinstances,asnecessary.

Definition at line 1394 of file ElementTree.py.


Constructor & Destructor Documentation

def xml.etree.ElementTree.TreeBuilder.__init__ (   self,
  element_factory = None 
)

Definition at line 1396 of file ElementTree.py.

01396 
01397     def __init__(self, element_factory=None):
01398         self._data = [] # data collector
01399         self._elem = [] # element stack
01400         self._last = None # last element
01401         self._tail = None # true if we're after an end tag
01402         if element_factory is None:
01403             element_factory = Element
01404         self._factory = element_factory

Here is the caller graph for this function:


Member Function Documentation

def xml.etree.ElementTree.TreeBuilder._flush (   self) [private]

Definition at line 1417 of file ElementTree.py.

01417 
01418     def _flush(self):
01419         if self._data:
01420             if self._last is not None:
01421                 text = "".join(self._data)
01422                 if self._tail:
01423                     assert self._last.tail is None, "internal error (tail)"
01424                     self._last.tail = text
01425                 else:
01426                     assert self._last.text is None, "internal error (text)"
01427                     self._last.text = text
01428             self._data = []

Here is the caller graph for this function:

Flushes the builder buffers, and returns the toplevel document element.

Returns:
An Element instance. Element

Definition at line 1412 of file ElementTree.py.

01412 
01413     def close(self):
01414         assert len(self._elem) == 0, "missing end tags"
01415         assert self._last is not None, "missing toplevel element"
01416         return self._last

Here is the caller graph for this function:

def xml.etree.ElementTree.TreeBuilder.data (   self,
  data 
)

Adds text to the current element.

Parameters:
dataA string. This should be either an 8-bit string containing ASCII text, or a Unicode string.

Definition at line 1435 of file ElementTree.py.

01435 
01436     def data(self, data):
01437         self._data.append(data)

Here is the caller graph for this function:

def xml.etree.ElementTree.TreeBuilder.end (   self,
  tag 
)

Closes the current element.

Parameters:
tagThe element name.
Returns:
The closed element. Element

Definition at line 1462 of file ElementTree.py.

01462 
01463     def end(self, tag):
01464         self._flush()
01465         self._last = self._elem.pop()
01466         assert self._last.tag == tag,\
01467                "end tag mismatch (expected %s, got %s)" % (
01468                    self._last.tag, tag)
01469         self._tail = 1
01470         return self._last

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.etree.ElementTree.TreeBuilder.start (   self,
  tag,
  attrs 
)

Opens a new element.

Parameters:
tagThe element name.
attribA dictionary containing element attributes.
Returns:
The opened element. Element

Definition at line 1446 of file ElementTree.py.

01446 
01447     def start(self, tag, attrs):
01448         self._flush()
01449         self._last = elem = self._factory(tag, attrs)
01450         if self._elem:
01451             self._elem[-1].append(elem)
01452         self._elem.append(elem)
01453         self._tail = 0
01454         return elem

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1397 of file ElementTree.py.

Definition at line 1398 of file ElementTree.py.

Definition at line 1403 of file ElementTree.py.

Definition at line 1399 of file ElementTree.py.

Definition at line 1400 of file ElementTree.py.


The documentation for this class was generated from the following file: