Package gavo :: Package utils :: Module stanxml :: Class Element
[frames] | no frames]

Class Element

source code

object --+
         |
        Element
Known Subclasses:

An element for serialization into XML.

This is loosely modelled after nevow stan.

Don't add to the children attribute directly, use addChild or (more usually) __getitem__.

Elements have attributes and children. The attributes are defined, complete with defaults, in _a_<name> attributes as in AutoNodes. Attributes are checked.

Children are not usually checked, but you can set a _childSequence attribute containing a list of (unqualified) element names. These children will be emitted in the sequence given.

When deriving from Elements, you may need attribute names that are not python identifiers (e.g., with dashes in them). In that case, define an attribute _name_a_<att> and point it to any string you want as the attribute.

When serializing these, empty elements (i.e. those having an empty text and having no non-empty children) are usually discarded. If you need such an element (e.g., for attributes), set mayBeEmpty to True.

Since insane XSD mandates that local elements must not be qualified when elementFormDefault is unqualified, you need to set _local=True on such local elements to suppress the namespace prefix. Attribute names are never qualified here. If you need qualified attributes, you'll have to use attribute name translation.

The content of the DOM may be anything recognized by addChild. In particular, you can give objects a serializeToXMLStan method returning strings or an Element to make them good DOM citizens.

Elements cannot harbor mixed content (or rather, there is only one piece of text).

Nested Classes
  __metaclass__
A metaclass used for Elements.
Instance Methods
 
__getitem__(self, children) source code
 
__call__(self, **kw) source code
 
__iter__(self) source code
 
__nonzero__(self) source code
 
bailIfBadChild(self, child) source code
 
deepcopy(self)
returns a deep copy of self.
source code
 
addChild(self, child)
adds child to the list of children.
source code
 
isEmpty(self)
returns true if the current node has no non-empty children and no non-whitespace text content.
source code
 
shouldBeSkipped(self)
returns true if the current node should be part of an output.
source code
 
iterAttNames(self)
iterates over the defined attribute names of this node.
source code
 
addAttribute(self, attName, attValue)
adds attName, attValue to this Element's attributes when instanciated.
source code
 
iterChildrenOfType(self, type)
iterates over all children having type.
source code
 
iterChildren(self) source code
 
getChildDict(self) source code
 
iterChildrenWithName(self, elName)
iterates over children whose element name is elName.
source code
 
apply(self, func)
calls func(node, text, attrs, childIter).
source code
 
asETree(self, prefixForEmpty=None)
returns an ElementTree instance for the tree below this node.
source code
 
render(self, prefixForEmpty=None, includeSchemaLocation=True)
returns this and its children as a string.
source code
 
__init__(self, id=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  name_ = None
hash(x)
Properties

Inherited from object: __class__

Method Details

addChild(self, child)

source code 

adds child to the list of children.

Child may be an Element, a string, or a list or tuple of Elements and strings. Finally, child may be None, in which case nothing will be added.

shouldBeSkipped(self)

source code 

returns true if the current node should be part of an output.

That is true if it is either non-empty or _mayBeEmpty is true. An empty element is one that has only empty children and no non-whitespace text content.

iterAttNames(self)

source code 

iterates over the defined attribute names of this node.

Each element returned is a pair of the node attribute name and the xml name (which may be translated via _a_name_<att>

addAttribute(self, attName, attValue)

source code 

adds attName, attValue to this Element's attributes when instanciated.

You cannot add _a_<attname> attributes to instances. Thus, when in a pinch, use this.

iterChildrenWithName(self, elName)

source code 

iterates over children whose element name is elName.

This always does a linear search through the children and hence may be slow.

apply(self, func)

source code 

calls func(node, text, attrs, childIter).

This is a building block for tree traversals; the expectation is that func does something like func(node, text, attrDict, childSequence).

asETree(self, prefixForEmpty=None)

source code 

returns an ElementTree instance for the tree below this node.

Deprecated. Use Serializer rather than ElementTree.

__init__(self, id=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)