Panda3D

- Main Page
- Packages
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions

# ElementTree Class Reference

ElementTree wrapper class. More...

List of all members.

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

## 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:

  element | Optional 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 __init__ | ( |  | self,
|  |  | element = `None`,
|  |  | file = `None`
| ) |  |

## Member Function Documentation

def find | ( |  | self,
|  |  | path
| ) |  |

Finds the first toplevel element with given tag.

Same as getroot().find(path).

Parameters:

  path | What element to look for.

Returns:
  The first matching element, or None if no element was found. Element or None

def findall | ( |  | self,
|  |  | path
| ) |  |

Finds all toplevel elements with the given tag.

Same as getroot().findall(path).

Parameters:

  path | What element to look for.

Returns:
  A list or iterator containing all matching elements, in document order. list of Element instances

def findtext | ( |  | self,
|  |  | path,
|  |  | default = `None`
| ) |  |

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

Same as getroot().findtext(path).

Parameters:

  path | What toplevel element to look for.
  default | What 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 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:

  tag | What tags to look for (default is to return all elements)

Returns:
  An iterator. iterator

def getroot | ( |  | self | ) |

Gets the root element for this tree.

Returns:
  An element instance. Element

def parse | ( |  | self,
|  |  | source,
|  |  | parser = `None`
| ) |  |

Loads an external XML document into this element tree.

Parameters:

  source | A file name or file object.
  parser | An optional parser instance. If not given, the standard XMLTreeBuilder parser is used.

Returns:
  The document root element. Element

def write | ( |  | self,
|  |  | file,
|  |  | encoding = `"us-ascii"`
| ) |  |

Writes the element tree to a file, as XML.

Parameters:

  file | A file name, or a file object opened for writing.
  encoding | Optional output encoding (default is US-ASCII).

All Classes Namespaces Functions Variables Enumerations Enumerator Properties