X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fxml.py;h=d6734e630d0484a7ae57144f3415a9c80cc0ef3a;hb=49aeb133ab3b334a2785886efedf5b9f2a3da23b;hp=1a7f2f373194b83e1e2aaba7d916232da5163418;hpb=a97d90d4ab620e7a6dd5c7da218d6d788726be70;p=sfa.git diff --git a/sfa/util/xml.py b/sfa/util/xml.py index 1a7f2f37..d6734e63 100755 --- a/sfa/util/xml.py +++ b/sfa/util/xml.py @@ -64,7 +64,7 @@ class XmlElement: namespaces = self.namespaces elems = self.element.xpath(xpath, namespaces=namespaces) return [XmlElement(elem, namespaces) for elem in elems] - + def add_element(self, tagname, **kwds): element = etree.SubElement(self.element, tagname, **kwds) return XmlElement(element, self.namespaces) @@ -195,11 +195,12 @@ class XML: self.namespaces['default'] = 'default' self.root = XmlElement(root, self.namespaces) - # set schema + # set schema for key in self.root.attrib.keys(): if key.endswith('schemaLocation'): - # schema location should be at the end of the list - schema_parts = self.root.attrib[key].split(' ') + # schemaLocation should be at the end of the list. + # Use list comprehension to filter out empty strings + schema_parts = [x for x in self.root.attrib[key].split(' ') if x] self.schema = schema_parts[1] namespace, schema = schema_parts[0], schema_parts[1] break @@ -208,7 +209,7 @@ class XML: if element is None: if self.root is None: self.parse_xml('<%s/>' % root_tag_name) - element = self.root + element = self.root.element if 'text' in d: text = d.pop('text') @@ -224,9 +225,9 @@ class XML: self.parse_dict(val, key, child_element) elif isinstance(val, basestring): child_element = etree.SubElement(element, key).text = val - + elif isinstance(value, int): - d[key] = unicode(d[key]) + d[key] = unicode(d[key]) elif value is None: d.pop(key) @@ -264,7 +265,7 @@ class XML: if not element: element = self.root element.remove_attribute(name) - + def add_element(self, *args, **kwds): """ Wrapper around etree.SubElement(). Adds an element to