DefTree API¶
Element¶
-
class
deftree.
Element
(name)¶ Element class. This class defines the Element interface
-
append
(item)¶ Inserts the item at the end of this element’s internal list of children. Raises TypeError if item is not a
Element
orAttribute
-
clear
()¶ Resets an element. This function removes all children, clears all attributes
-
get_attribute
(name[, value])¶ Returns the first
Attribute
instance whose name matches name and if value is not None whose value equal value. If none is found it returns None.
-
get_element
(name)¶ Returns the first
Element
whose name matches name, if none is found returns None.
-
index
(item)¶ Returns the index of the item in this element, raises ValueError if not found.
-
insert
(index, item)¶ Inserts the item at the given position in this element. Raises TypeError if item is not a
Element
orAttribute
-
iter_all
()¶ Creates a tree iterator with the current element as the root. The iterator iterates over this element and all elements below it, in document (depth first) order. Both
Element
andAttribute
are returned from the iterator.
-
iter_attributes
()¶ Creates a tree iterator with the current element as the root. The iterator iterates over this element and all elements below it, in document (depth first) order. Only
Attributes
are returned from the iterator.
-
iter_elements
()¶ Creates a tree iterator with the current element as the root. The iterator iterates over this element and all elements below it, in document (depth first) order. Only
Element
are returned from the iterator.
-
iter_find_attributes
(name[, value])¶ Creates a tree iterator with the current element as the root. The iterator iterates over this element and all elements below it, in document (depth first) order. Only
Attributes
whose name equals name, and if value is not None whose value equal value are returned from the iterator
-
Attribute¶
DefTree¶
-
class
deftree.
DefTree
¶ DefTree class. This class represents an entire element hierarchy.
-
dump
()¶ Write the the DefTree structure to sys.stdout. This function should be used for debugging only.
-
from_string
(text[, parser])¶ Parses a Defold document section from a string constant which it returns. parser is an optional parser instance. If not given the standard parser is used. Returns the root of
DefTree
.
-
parse
(source[, parser])¶ Parses a Defold document into a
DefTree
which it returns. source is a file_path. parser is an optional parser instance. If not given the standard parser is used.
-
write
(file_path)¶ Writes the element tree to a file, as plain text. file_path needs to be a path
-
Helpers¶
-
deftree.
SubElement
(parent, name)¶ SubElement factory which creates an element instance with name, and appends it to an existing parent.
-
deftree.
parse
(source)¶ Parses a Defold document into a DefTree which it returns. source is a file_path. parser is an optional parser instance. If not given the standard parser is used.