xml.etree.ElementTree.TreeBuilder

class xml.etree.ElementTree.TreeBuilder(element_factory=None)

Generic element structure builder. This builder converts a sequence of start, data, and end method calls to a well-formed element structure. You can use this class to build an element structure using a custom XML parser, or a parser for some other XML-like format. element_factory, when given, must be a callable accepting two positional arguments: a tag and a dict of attributes. It is expected to return a new element instance.

close()

Flushes the builder buffers, and returns the toplevel document element. Returns an Element instance.

data(data)

Adds text to the current element. data is a string. This should be either a bytestring, or a Unicode string.

end(tag)

Closes the current element. tag is the element name. Returns the closed element.

start(tag, attrs)

Opens a new element. tag is the element name. attrs is a dictionary containing element attributes. Returns the opened element.

In addition, a custom TreeBuilder object can provide the following method:

doctype(name, pubid, system)

Handles a doctype declaration. name is the doctype name. pubid is the public identifier. system is the system identifier. This method does not exist on the default TreeBuilder class.

New in version 3.2.

doc_python
2016-10-07 17:48:05
Comments
Leave a Comment

Please login to continue.