X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=xml;h=8bc536f24e9a6a87839479514e42d8535c20aa7f;hb=00a366effbc6bdf9784b5db07b1c693b622836e5;hp=e78e47e4bc20d13403eb85f7cf8b43591ec18fdf;hpb=db63b272c4064cfc541f89f70aa8354ee6920905;p=extfs.d.git diff --git a/xml b/xml index e78e47e..8bc536f 100755 --- a/xml +++ b/xml @@ -158,6 +158,15 @@ class XmlVfs(object): len(text), subpath_encoded) self._list(element, subpath) + def get_tag_node(self, node, i): + n = 0 + for element in self.getchildren(node): + if self.istag(element): + n += 1 + if n == i: + return element + xml_error('There are less than %d nodes' % i) + def attrs2text(self, node): attr_accumulator = [] for name, value in self.getattrs(node): @@ -169,15 +178,6 @@ class XmlVfs(object): def has_ns(self, node): return False - def get_child_node(self, node, i): - n = 0 - for element in self.getchildren(node): - if self.istag(element): - n += 1 - if n == i: - return element - xml_error('There are less than %d nodes' % i) - class MiniDOMXmlVfs(XmlVfs): def parse(self): @@ -237,9 +237,6 @@ if use_elementtree or use_lxml: if text: text_accumulator.append(text) return '\n'.join(text_accumulator).encode(default_encoding, "replace") - def getroot(self): - return self.document.getroot() - def getchildren(self, node): return list(node) @@ -280,6 +277,9 @@ if use_elementtree: self.document = ET.parse(sys.argv[2], PIParser()) + def getroot(self): + return self.document.getroot() + def getlocalname(self, name): if name.startswith('{'): name = name.split('}', 1)[1] # Remove XML namespace @@ -293,6 +293,12 @@ if use_lxml: def parse(self): self.document = etree.parse(sys.argv[2]) + def getroot(self): + return [self.document.getroot()] + + def getlocalname(self, name): + return etree.QName(name).localname + def has_ns(self, node): return bool(node.nsmap) @@ -304,12 +310,6 @@ if use_lxml: ns_accumulator.append("%s=%s" % (name, value)) return '\n'.join(ns_accumulator) - def getroot(self): - return [self.document.getroot()] - - def getlocalname(self, name): - return etree.QName(name).localname - def build_xmlvfs(): if force_implementation is None: @@ -347,7 +347,7 @@ def mcxml_copyout(): for path_comp in xml_filename.split('/'): if ' ' in path_comp: i = int(path_comp.split(' ', 1)[0]) - node = xmlvfs.get_child_node(node, i) + node = xmlvfs.get_tag_node(node, i) elif path_comp in ('attributes', 'namespaces', 'text'): break else: