| |
- SXMLTemplate
class SXMLTemplate |
|
Base class for Simple XML Templates
It generates a XML DOM document that is based on a xml template source (file, string ...)
that will be filled with external data by appending the selected new xml elements with
data. Into XML input template, it changes all keys with the format $(key|defautlvalue)s
into the data of "key" from the param dictionary, or "defaultvalue" if key is not found
in dictionary.
Public Attibutes:
:param sizeLimit: = 1024 -> (bytes) max size of template source.
:param separatorKey: = "|" -> separator for default key values.
:param separatorXml: = "." -> separator to indicates repeateable elements.
:param defaultValue: = "NULL" -> default value for keys without default values. |
|
Methods defined here:
- __init__(self, source, redoelements=[])
- SXMLTemplate class constructor
:Parameters:
-`source`: URI, filename, or string of XML template.
-`redoelements`: list of XML nodes to repeat into XML with data.
- __str__(self)
- Dumps the XML DOM structure from memory with indent like "toprettyxml" function
from "xml.dom.minidom" module.
- getDom(self, template=False)
- Get a DOM object.
:Parameters:
-`template`: "True" returns original template. "False" returns current XML with data.
- setData(self, data, lwhere=[])
- It sets up data for "repeatable" nodes of template.
This function clones the "repeatable" nodes from template and fills it with data
from the dictionary.
:Parameters:
-`data`: dictionary with data for new XML nodes.
-`lwhere`: list of nodes which will be filled with data.
- setRootInfo(self, data)
- It sets up basic data for not "repeatable" nodes (root XML elements) of template.
:Parameters:
-`data`: dictionary with data for base nodes of template.
- setTemplates(self, redoelements=[])
- Sets up the list of nodes of template to be repeated with new data.
With each value, these nodes will be created with new data.
Each node is indicated with the format: "xmlrootnode.subnode---subnode.node"
:Parameters:
-`redoelements`: list of XML nodes to repeat into XML.
Data and other attributes defined here:
- TemplateDict = <class 'sxmltemplate.TemplateDict'>
- Class for string templates with dictionaries objects and operator %
This class inherits all attributes, methods, ... from dict and redefines "__getitem__"
in order to return a default value when an element is not found. The format
"key<separator>defaultvalue" indicates that if "key" is not found, then "defaultvalue"
will be returned. It is like an OR: returns value or "defaultvalue".
It is posible to define a global default value for all keys.
- defaultValue = 'NULL'
- separatorKey = '|'
- separatorXml = '.'
- sizeLimit = 1048576
| |