diff --git a/pisi/xmlfile.py b/pisi/xmlfile.py index c9701f29..a4e5f0b4 100644 --- a/pisi/xmlfile.py +++ b/pisi/xmlfile.py @@ -505,8 +505,12 @@ class autoxml(oo.autosuper): def gen_list_tag(cls, tag, spec): """generate a list datatype. stores comps in tag/comp_tag""" - name, tag_type, req, comp_tag = cls.parse_spec(tag, spec) + name, tag_type, req, path = cls.parse_spec(tag, spec) #head, last = cls.tagpath_head_last(path) + pathcomps = path.split('/') + list_tagpath = path[:path.rfind('/')] + comp_tag = pathcomps[len(pathcomps)-1] + #TODO: make default path ... tag + '/' + comp_tag when comp is class! if len(tag_type) != 1: raise Error(_('List type must contain only one element')) @@ -519,7 +523,7 @@ class autoxml(oo.autosuper): def decode(node, errs, where): l = [] - nodes = getAllNodes(node, tag + '/' + comp_tag) + nodes = getAllNodes(node, path) #print node, tag + '/' + comp_tag, nodes if len(nodes) is 0 and req is mandatory: errs.append(where + _('Mandatory list empty')) @@ -531,11 +535,13 @@ class autoxml(oo.autosuper): return l def encode(xml, node, l, errs): + dom = node.ownerDocument if l and len(l) > 0: - listnode = xml.newNode(tag) for item in l: + listnode = xml.newNode("Dummy") encode_item(xml, listnode, item, errs) - node.appendChild(listnode) + node = getNode(listnode, comp_tag) + addNode(dom, node, path) else: if req is mandatory: errs.append(_('Mandatory list empty')) diff --git a/tests/a.xml b/tests/a.xml index 4ca73e79..2293bbcd 100644 --- a/tests/a.xml +++ b/tests/a.xml @@ -5,11 +5,9 @@ 868 Lazy Tin Tembel Teneke - pisi noatun kdevelop - 18071976 AI diff --git a/tests/xmlfiletests.py b/tests/xmlfiletests.py index 5a014369..9bc857db 100644 --- a/tests/xmlfiletests.py +++ b/tests/xmlfiletests.py @@ -32,7 +32,7 @@ class XmlFileTestCase(unittest.TestCase): __metaclass__ = xmlfile.autoxml t_BirthDate = [types.StringType, xmlfile.mandatory] t_Interest = [types.StringType, xmlfile.optional] - t_CodesWith = [ [types.StringType], xmlfile.optional, 'Person'] + t_CodesWith = [ [types.StringType], xmlfile.optional, 'CodesWith/Person'] class A(xmlfile.XmlFile): __metaclass__ = xmlfile.autoxml @@ -41,14 +41,14 @@ class XmlFileTestCase(unittest.TestCase): t_Number = [types.IntType, xmlfile.optional] t_Email = [types.StringType, xmlfile.optional] a_href = [types.StringType, xmlfile.mandatory] - t_Projects = [ [types.StringType], xmlfile.mandatory, 'Project', ''] + t_Projects = [ [types.StringType], xmlfile.mandatory, 'Project'] t_OtherInfo = [ OtherInfo, xmlfile.optional ] a = A() self.assertEqual(a.href, None) dom = mdom.parse('tests/a.xml') node = getNode(dom, 'A') - self.assert_(len(A.decoders)>0) + self.assertEqual(len(A.decoders), 4) errs = [] print 'errs', errs a.decode(node, errs)