Package bridge :: Class Element
[show private | hide private]
[frames | no frames]

Type Element

object --+
         |
        Element

Known Subclasses:
Document

Maps an XML element to a Python object.
Method Summary
  __init__(self, name, content, attributes, prefix, namespace, parent)
Maps an XML element to a Python object.
  __copy__(self)
  __delattr__(self, name)
deletes 'name' instance of Element.
  __iter__(self)
  __repr__(self)
  __str__(self)
  __unicode__(self)
  clone(self)
  collapse(self, separator)
Collapses all content of this element and its entire subtree.
  filtrate(self, some_filter, **kwargs)
Applies a filter to this element.
  forget(self)
deletes this instance of Element.
  get_attribute(self, name)
  get_attribute_ns(self, name, namespace)
  get_child(self, name, ns)
Returns the child element named 'name', None if not found.
  get_children(self, name, ns, recursive)
Returns the all children of this element named 'name'
  get_root(self)
  has_child(self, name, ns)
Checks if this element has a child named 'name' in its children elements
  has_element(self, name, ns)
Checks if this element has 'name' attribute
  insert_after(self, after_element, element)
Insert 'element' right after 'after_element'.
  insert_before(self, before_element, element)
Insert 'element' right before 'before_element'.
  is_mixed_content(self)
Returns True if the direct children of this element makes are in mixed content.
  load(self, source, prefixes, as_attribute, as_list, as_attribute_of_element, parser)
Load source into an Element instance (Class method)
  update_prefix(self, dst, srcns, dstns, update_attributes)
Updates prefixes of all the element of document matching (src, srcns)
  validate(self, validator, **kwargs)
Applies a validator on this element
  xml(self, indent, encoding, prefixes, omit_declaration, parser)
Serializes as a string this element
    Inherited from object
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Property Summary
  xml_root: Retrieve the top level element

Class Variable Summary
NoneType as_attribute = None                                                                  
NoneType as_list = None                                                                  
str encoding = 'UTF-8'

Instance Method Details

__init__(self, name=None, content=None, attributes=None, prefix=None, namespace=None, parent=None)
(Constructor)

Maps an XML element to a Python object.

Keyword arguments: name -- Name of the XML element content -- Content of the element attributes -- dictionary of the form {local_name: value} prefix -- XML prefix of the element namespace -- XML namespace attached to that element parent -- Parent element of this element.

If 'parent' is not None, 'self' will be added to the parent.xml_children

If 'Element.as_list' is set and if (name, namespace) belongs to it then we will add a list to parent with the name of the element

If 'Element.as_attribute' is set and if (name, namespace) belongs to it then we will add an attribute to parent with the name of the element
Overrides:
__builtin__.object.__init__

__delattr__(self, name)

deletes 'name' instance of Element. It will also removes it from its parent children and attributes.
Overrides:
__builtin__.object.__delattr__

collapse(self, separator='\n')

Collapses all content of this element and its entire subtree.

filtrate(self, some_filter, **kwargs)

Applies a filter to this element. Returns what is returned from some_filter.

Keyword arguments: some_filter -- a callable(**kwargs)

forget(self)

deletes this instance of Element. It will also removes it from its parent children and attributes.

get_child(self, name, ns=None)

Returns the child element named 'name', None if not found.

Keyword arguments: name -- local name of the element ns -- namespace of the element

get_children(self, name, ns=None, recursive=False)

Returns the all children of this element named 'name'

Keyword arguments: name -- local name of the element ns -- namespace of the element recursive -- if True this will iterate through the entire tree

has_child(self, name, ns=None)

Checks if this element has a child named 'name' in its children elements

Keyword arguments: name -- local name of the element ns -- namespace of the element

has_element(self, name, ns=None)

Checks if this element has 'name' attribute

Keyword arguments: name -- local name of the element ns -- namespace of the element

insert_after(self, after_element, element)

Insert 'element' right after 'after_element'. This only inserts the new element in self.xml_children

Keyword arguments: after_element -- element pivot element -- new element to insert

insert_before(self, before_element, element)

Insert 'element' right before 'before_element'. This only inserts the new element in self.xml_children

Keyword arguments: before_element -- element pivot element -- new element to insert

is_mixed_content(self)

Returns True if the direct children of this element makes are in mixed content.

update_prefix(self, dst, srcns, dstns, update_attributes=True)

Updates prefixes of all the element of document matching (src, srcns)

Keyword arguments: dst -- new prefix to be used srcns -- source namespace dstns -- destination namespace update_attributes -- update attributes' namespace as well (default: True)

validate(self, validator, **kwargs)

Applies a validator on this element

xml(self, indent=True, encoding='UTF-8', prefixes=None, omit_declaration=False, parser=None)

Serializes as a string this element

Keyword arguments indent -- pretty print the XML string (defaut: True) encoding -- encoding to use during the serialization process prefixes -- dictionnary of prefixes of the form {'prefix': 'ns'} omit_declaration -- prevent the result to start with the XML declaration parser -- instance of an existing parser, if not provided the default one will be used

Class Method Details

load(self, source, prefixes=None, as_attribute=None, as_list=None, as_attribute_of_element=None, parser=None)

Load source into an Element instance

Keyword arguments: source -- an XML string, a file path or a file object prefixes -- dictionnary of prefixes of the form {'prefix': 'ns'} as_attribute -- dictionary of element names to set as attribute of their parent as_list -- dictionary of element names to set into a list of their parent as_attribute_of_element -- dictionary of attribute names to set as attribute of their parent

If any of those last three parameters are provided they will take precedence over those set on the Element and Attribute class.

Property Details

xml_root

Retrieve the top level element
Get Method:
get_root(self)

Class Variable Details

as_attribute

Type:
NoneType
Value:
None                                                                  

as_list

Type:
NoneType
Value:
None                                                                  

encoding

Type:
str
Value:
'UTF-8'                                                                

Generated by Epydoc 2.1 on Tue May 22 18:09:00 2007 http://epydoc.sf.net