odf.element.Element Class Reference

Creates a arbitrary element and is intended to be subclassed not used on its own. More...

Inheritance diagram for odf.element.Element:
[legend]
Collaboration diagram for odf.element.Element:
[legend]

## Public Member Functions

def | __init__ (self, attributes=None, text=None, cdata=None, qname=None, qattributes=None, check_grammar=True, args)
def | get_knownns (self, prefix)
| Odfpy maintains a list of known namespaces. More...
def | get_nsprefix (self, namespace)
| Odfpy maintains a list of known namespaces. More...
def | allowed_attributes (self)
def | addElement (self, element, check_grammar=True)
| adds an element to an Element More...
def | addText (self, text, check_grammar=True)
| Adds text to an element Setting check_grammar=False turns off grammar checking. More...
def | addCDATA (self, cdata, check_grammar=True)
| Adds CDATA to an element Setting check_grammar=False turns off grammar checking. More...
def | removeAttribute (self, attr, check_grammar=True)
| Removes an attribute by name. More...
def | setAttribute (self, attr, value, check_grammar=True)
| Add an attribute to the element This is sort of a convenience method. More...
def | setAttrNS (self, namespace, localpart, value)
| Add an attribute to the element In case you need to add an attribute the library doesn't know about then you must provide the full qualified name It will not check that the attribute is legal according to the schema. More...
def | getAttrNS (self, namespace, localpart)
| gets an attribute, given a namespace and a key More...
def | removeAttrNS (self, namespace, localpart)
def | getAttribute (self, attr)
| Get an attribute value. More...
def | write_open_tag (self, level, f)
def | write_close_tag (self, level, f)
def | toXml (self, level, f)
| Generate an XML stream out of the tree structure. More...
def | getElementsByType (self, element)
| Gets elements based on the type, which is function from text.py, draw.py etc. More...
def | isInstanceOf (self, element)
| This is a check to see if the object is an instance of a type. More...
Public Member Functions inherited from odf.element.Node
def | hasChildNodes (self)
| Tells whether this element has any children; text nodes, subelements, whatever. More...
def | insertBefore (self, newChild, refChild)
| Inserts the node newChild before the existing child node refChild. More...
def | appendChild (self, newChild)
| Adds the node newChild to the end of the list of children of this node. More...
def | removeChild (self, oldChild)
| Removes the child node indicated by oldChild from the list of children, and returns it. More...
def | __str__ (self)
def | __unicode__ (self)

## Public Attributes

| qname
| ownerDocument
| childNodes
| allowed_children
| tagName
| attributes

## Static Public Attributes

| nodeType = Node.ELEMENT_NODE
dictionary | namespaces = {}
Static Public Attributes inherited from odf.element.Node
| parentNode = None
| nextSibling = None
| previousSibling = None

## Detailed Description

Creates a arbitrary element and is intended to be subclassed not used on its own.

This element is the base of every element it defines a class which resembles a xml-element. The main advantage of this kind of implementation is that you don't have to create a toXML method for every different object. Every element consists of an attribute, optional subelements, optional text and optional cdata.

Definition at line 357 of file element.py.

## Constructor & Destructor Documentation

## __init__()

def odf.element.Element.__init__ | ( |  | self,
|  |  | attributes = `None`,
|  |  | text = `None`,
|  |  | cdata = `None`,
|  |  | qname = `None`,
|  |  | qattributes = `None`,
|  |  | check_grammar = `True`,
|  |  | args
| ) |  |

Definition at line 369 of file element.py.

## Member Function Documentation

## addCDATA()

def odf.element.Element.addCDATA | ( |  | self,
|  |  | cdata,
|  |  | check_grammar = `True`
| ) |  |

Adds CDATA to an element Setting check_grammar=False turns off grammar checking.

Definition at line 469 of file element.py.

Here is the call graph for this function:

## addElement()

def odf.element.Element.addElement | ( |  | self,
|  |  | element,
|  |  | check_grammar = `True`
| ) |  |

adds an element to an Element

Element.addElement(Element)

Definition at line 445 of file element.py.

Here is the call graph for this function:

## addText()

def odf.element.Element.addText | ( |  | self,
|  |  | text,
|  |  | check_grammar = `True`
| ) |  |

Adds text to an element Setting check_grammar=False turns off grammar checking.

Definition at line 458 of file element.py.

Here is the call graph for this function:

## allowed_attributes()

def odf.element.Element.allowed_attributes | ( |  | self | ) |

Definition at line 432 of file element.py.

Here is the call graph for this function:
Here is the caller graph for this function:

## get_knownns()

def odf.element.Element.get_knownns | ( |  | self,
|  |  | prefix
| ) |  |

Odfpy maintains a list of known namespaces.

In some cases a prefix is used, and we need to know which namespace it resolves to.

Definition at line 415 of file element.py.

## get_nsprefix()

def odf.element.Element.get_nsprefix | ( |  | self,
|  |  | namespace
| ) |  |

Odfpy maintains a list of known namespaces.

In some cases we have a namespace URL, and needs to look up or assign the prefix for it.

Definition at line 425 of file element.py.

Here is the caller graph for this function:

## getAttribute()

def odf.element.Element.getAttribute | ( |  | self,
|  |  | attr
| ) |  |

Get an attribute value.

The method knows which namespace the attribute is in

Definition at line 564 of file element.py.

Here is the call graph for this function:

## getAttrNS()

def odf.element.Element.getAttrNS | ( |  | self,
|  |  | namespace,
|  |  | localpart
| ) |  |

gets an attribute, given a namespace and a key

Parameters

  namespace | a unicode string or a bytes: the namespace
  localpart | a unicode string or a bytes: the key to get the attribute

Returns
  an attribute as a unicode string or a bytes: if both paramters are byte strings, it will be a bytes; if both attributes are unicode strings, it will be a unicode string

Definition at line 545 of file element.py.

Here is the call graph for this function:
Here is the caller graph for this function:

## getElementsByType()

def odf.element.Element.getElementsByType | ( |  | self,
|  |  | element
| ) |  |

Gets elements based on the type, which is function from text.py, draw.py etc.

Definition at line 623 of file element.py.

Here is the call graph for this function:

## isInstanceOf()

def odf.element.Element.isInstanceOf | ( |  | self,
|  |  | element
| ) |  |

This is a check to see if the object is an instance of a type.

Definition at line 629 of file element.py.

## removeAttribute()

def odf.element.Element.removeAttribute | ( |  | self,
|  |  | attr,
|  |  | check_grammar = `True`
| ) |  |

Removes an attribute by name.

Definition at line 477 of file element.py.

Here is the call graph for this function:

## removeAttrNS()

def odf.element.Element.removeAttrNS | ( |  | self,
|  |  | namespace,
|  |  | localpart
| ) |  |

Definition at line 558 of file element.py.

Here is the caller graph for this function:

## setAttribute()

def odf.element.Element.setAttribute | ( |  | self,
|  |  | attr,
|  |  | value,
|  |  | check_grammar = `True`
| ) |  |

Add an attribute to the element This is sort of a convenience method.

All attributes in ODF have namespaces. The library knows what attributes are legal and then allows the user to provide the attribute as a keyword argument and the library will add the correct namespace. Must overwrite, If attribute already exists.

Definition at line 501 of file element.py.

Here is the call graph for this function:

## setAttrNS()

def odf.element.Element.setAttrNS | ( |  | self,
|  |  | namespace,
|  |  | localpart,
|  |  | value
| ) |  |

Add an attribute to the element In case you need to add an attribute the library doesn't know about then you must provide the full qualified name It will not check that the attribute is legal according to the schema.

Must overwrite, If attribute already exists.

Definition at line 527 of file element.py.

Here is the call graph for this function:
Here is the caller graph for this function:

## toXml()

def odf.element.Element.toXml | ( |  | self,
|  |  | level,
|  |  | f
| ) |  |

Generate an XML stream out of the tree structure.

Parameters

  level | integer: level in the XML tree; zero at root of the tree
  f | an open writable file able to accept unicode strings

Definition at line 597 of file element.py.

Here is the call graph for this function:

## write_close_tag()

def odf.element.Element.write_close_tag | ( |  | self,
|  |  | level,
|  |  | f
| ) |  |

Definition at line 588 of file element.py.

## write_open_tag()

def odf.element.Element.write_open_tag | ( |  | self,
|  |  | level,
|  |  | f
| ) |  |

Definition at line 578 of file element.py.

Here is the call graph for this function:

## Member Data Documentation

## allowed_children

odf.element.Element.allowed_children

Definition at line 375 of file element.py.

## attributes

odf.element.Element.attributes

Definition at line 386 of file element.py.

## childNodes

odf.element.Element.childNodes

Definition at line 374 of file element.py.

## namespaces

dictionary odf.element.Element.namespaces = {}

static

Definition at line 360 of file element.py.

## nodeType

odf.element.Element.nodeType = Node.ELEMENT_NODE

static

Definition at line 359 of file element.py.

## ownerDocument

odf.element.Element.ownerDocument

Definition at line 373 of file element.py.

## qname

odf.element.Element.qname

Definition at line 371 of file element.py.

## tagName

odf.element.Element.tagName

Definition at line 377 of file element.py.

The documentation for this class was generated from the following file:

- odf/element.py