Tool for generating XML-files from a template
by Swing Entwicklung betrieblicher Informationssysteme GmbH http://www.swing-system.comAvailability |
Odoo Online
Odoo.sh
On Premise
|
Technical Name |
xml_template |
License | AGPL-3 |
Website | http://www.swing-system.com |
Versions | 8.0 |
Generates XML-Files from a Template
The structure and features of the XML-Template:
The XML-template ist copied "as-is" to the output XML-file:
yields:
Additional control-attributes allow to fill the output XML with data from the data-model:
will produce:
provided that the Python expression "root.foo" will return "FOO" and "root.bar" will return "BAR" I.e., "attr-name[0-9]" provides an attribute-name and "attr-eval[0-9]" provides a Python-expression. The "[0-9]" can be any integer as long as "name" and "eval" matches.
List-iterations can be provided with the attributes "loop-eval" and "var":
will produce
A variant of this, "seq-eval" is necessary, if there is no surrounding tag for the list (which is a weak XML-design - but cannot be excluded):
will produce
The option "omit_on_empty" is used, if the surrounding tag shall be omitted with empty lists:
will produce
On the other hand:
will produce
The programmatic interface (API) of the XML-Template:
def generate_xml(self, cr, uid, id, nsmap=None, **scope_dict)
returns the output XMl. If a schema is provided, the validity is checked.
def attach_xml(self, cr, uid, id, attach_to, xml, name, fname, description, context)
creates an attachment from the output XML and attaches it to another object.
def write_file(self, cr, uid, id, xml, filename)
writes the output XML to a (server-side) provided file.
Example-Code (generate a XML for an invoice and attach it to that invoice):
Please log in to comment on this module