From 504c545cd7e1879e0f46752557104671a55ef8b4 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 16 Sep 2010 13:47:26 +0200 Subject: [PATCH] [IMP] tools/convert: allow multiple root elements in view architectures (all fields with type=xml) bzr revid: odo@openerp.com-20100916114726-9u10bm9k57nrwht5 --- bin/tools/convert.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bin/tools/convert.py b/bin/tools/convert.py index a90de107b29..a8749514958 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -68,6 +68,24 @@ def _obj(pool, cr, uid, model_str, context=None): model = pool.get(model_str) return lambda x: model.browse(cr, uid, x, context=context) +def _fix_multiple_roots(node): + """ + Surround the children of the ``node`` element of an XML field with a + single root "data" element, to prevent having a document with multiple + roots once parsed separately. + + XML nodes should have one root only, but we'd like to support + direct multiple roots in our partial documents (like inherited view architectures). + As a convention we'll surround multiple root with a container "data" element, to be + ignored later when parsing. + """ + + if len(node) > 1: + data_node = etree.Element("data") + for child in node: + data_node.append(child) + node.append(data_node) + def _eval_xml(self, node, pool, cr, uid, idref, context=None): if context is None: context = {} @@ -115,6 +133,7 @@ def _eval_xml(self, node, pool, cr, uid, idref, context=None): if not id in idref: idref[id]=self.id_get(cr, False, id) return s % idref + _fix_multiple_roots(node) return '\n'\ +_process("".join([etree.tostring(n, encoding='utf-8') for n in node]),