- def attrs2text(self, node):
- attr_accumulator = []
- for name, value in node.attrib.items():
- name = etree.QName(name).localname.encode(default_encoding, "replace")
- value = value.encode(default_encoding, "replace")
- attr_accumulator.append("%s=%s" % (name, value))
- return '\n'.join(attr_accumulator)
+ def getroot(self):
+ return [self.document.getroot()]
+
+ def get_root_comments(self):
+ text_accumulator = []
+ for element in self.document.getroot().itersiblings(
+ tag=etree.Comment, preceding=True):
+ text = u"<!--%s-->" % element.text
+ text_accumulator.append(text)
+ return '\n'.join(text_accumulator).encode(
+ default_encoding, "replace")
+
+ def getlocalname(self, name):
+ return etree.QName(name).localname
+
+ def _get_local_ns(self, node):
+ this_nsmap = node.nsmap
+ parent = node.getparent()
+ if parent is not None:
+ parent_nsmap = parent.nsmap
+ for key in parent_nsmap:
+ if this_nsmap[key] == parent_nsmap[key]:
+ del this_nsmap[key]
+ return this_nsmap