Package EaseXML :: Module main :: Class XMLObject
[show private | hide private]
[frames | no frames]

Type XMLObject

object --+
         |
        XMLObject

Known Subclasses:
Attribute, AttributeGroup, Choice, ComplexType, Element, Enumeration, Group, Schema, Sequence, SimpleType

Class attributes of interest:

If you pass the keyword main=True to one of your Nodes, it will be hooked so that calling Node methods ('append' for instance) from the XMLObject instance will be applied to that main Node:

class Other(XMLObject):
    boo = StringAttribute(default='titi')

class Single(XMLObject):
    content = ChoiceNode(['Other','Single'], noLimit=True, main=True)
    title = StringAttribute()

single = Single()
single.title = 'Foo'
single.append(Other())
single.append(Other())
single.append(single)

<Single title="Foo">
  <Other boo="titi"/>
  <Other boo="titi"/>
  <Single title="Foo">
    <Other boo="titi"/>
    <Other boo="titi"/>
  </Single>
</Single>

Method Summary
  __init__(self, *args, **kw)
  __cmp__(self, other)
Two XMLObjects are equal if they have the same XML representation
  __eq__(self, other)
  __getattr__(self, attrName)
  __getitem__(self, attrName)
  __ne__(self, other)
  __str__(self)
  forEach(self, callableFunc, *args, **kw)
Execute an action for each Node handled by an XMLObject.
  fromDict(cls, aDict)
Build an XMLObject given its dict representation. (Class method)
  fromXml(cls, xmlData)
Feeding an XMLObject instance with XML string data. (Class method)
  get(self, nodeName)
Fetch a node value given its name.
  getChildren(self)
Basic Introspection
  getClassName(cls)
(Class method)
  getEntities(self)
Get all entities specified in the xmlobject:
  getName(cls)
Fetch XMLObject's instance name which can be redefined by _name class attribute. (Class method)
  getNodes(self)
Sub-Nodes accessor
  getNodeWithName(self, nodeName)
Specific-Node accessor
  getParentNode(self)
Accessing the parent Node instance.
  orderAttrs(self)
  orderNodes(self, nodesList)
XMLObject remembers its children by a hash storage.
  set(self, nodeName, val)
Modify a node value given its name.
  setName(self, newName)
  setParentNode(self, node)
Setting the parent Node instance.
  toDict(self)
Fetch an XMLObject instance's data in a hash mapped by Node name
  toXml(self, headers, tabLength, prettyPrint)
Exporting an XMLObject instance to XML.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __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
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Class Variable Summary
str __name__ = 'XMLObject'
dict __nodes__ = {'xmlProcessingInstruction': <EaseXML.Node.P...
dict __ns_nodes__ = {}

Instance Method Details

__cmp__(self, other)
(Comparison operator)

Two XMLObjects are equal if they have the same XML representation

forEach(self, callableFunc, *args, **kw)

Execute an action for each Node handled by an XMLObject.

The head XML processing instruction is ignored. The callableFunc may have the following prototype:

def myCallable(node, xmlObject, *args, **kw):
    # do some things with the node ?
    pass

node is the Node instance to apply user-defined action. xmlObject is the XMLObject instance handling this node. args and kw store the content of their homonyms in the forEach method prototype.

Warning: This method can be very CPU-expensive if the XMLObject is deep (nested ListNodes and/or ChoiceNodes) because it make use of a recursion mechanism.

get(self, nodeName)

Fetch a node value given its name. using directly (or implicitely) getattr is smarter. This method is used by the MetaAttribute instances

getChildren(self)

Basic Introspection

Fetch XMLObject node names.

getEntities(self)

Get all entities specified in the xmlobject:

This method merges the two entities lists.

getNodes(self)

Sub-Nodes accessor

Fetch XMLObject nodes. Return a hash. This method differs from toDict in the way that the hash stores Node class instances. So it'd be more useful if the developer wants to inspect an XMLObject instance.

getNodeWithName(self, nodeName)

Specific-Node accessor

Return a Node instance given its name. Return None if Node doesn't exist under nodeName.

getParentNode(self)

Accessing the parent Node instance.

Return a dummy Node() by default (see __init__).

orderNodes(self, nodesList=None)

XMLObject remembers its children by a hash storage. Since hash sorting is not really friendly, this method returns two lists (nodeNames & nodes).

set(self, nodeName, val)

Modify a node value given its name. Same external behaviour as setattr This method is used by the MetaAttribute instances

setParentNode(self, node)

Setting the parent Node instance.

When XMLObjects are stored in ChoiceNodes or in ListNodes, we need to keep track of their parent. This method is mainly used by back-storage {Mixed,Typed}List instances used respectively by ChoiceNodes and ListNodes.

toDict(self)

Fetch an XMLObject instance's data in a hash mapped by Node name

This method provides instant access to all data stored by an XMLObject instance.

toXml(self, headers=1, tabLength=2, prettyPrint=True)

Exporting an XMLObject instance to XML.

Optionnal keyword parameters are:

  • headers : boolean to figure out if XML data has to be headed by the processing instruction(s) (like <?xml ..?>)
  • tabLength: XML indentation length

Return a string representing the XMLObject instance


Class Method Details

fromDict(cls, aDict)

Build an XMLObject given its dict representation.

fromXml(cls, xmlData)

Feeding an XMLObject instance with XML string data.

xmlData is parsed by xml.dom.minidom.parseString. The resulting DOM tree is then used to build Nodes recursively.

getName(cls)

Fetch XMLObject's instance name which can be redefined by _name class attribute. Space (' ') characters are replaced by underscores ('_') in returned result.

Class Variable Details

__name__

Type:
str
Value:
'XMLObject'                                                            

__nodes__

Type:
dict
Value:
{'xmlProcessingInstruction': <EaseXML.Node.ProcessingInstructionNode o\
bject at 0xb7db308c>}                                                  

__ns_nodes__

Type:
dict
Value:
{}                                                                     

Generated by Epydoc 2.1 on Sun Dec 12 17:20:24 2004 http://epydoc.sf.net