"""
-__version__ = "1.0.1"
+__version__ = "1.1.0"
__author__ = "Oleg Broytman <phd@phdru.name>"
__copyright__ = "Copyright (C) 2013 PhiloSoft Design"
__license__ = "GPL"
self.parse()
def list(self):
+ root_comments = self.get_root_comments()
+ if root_comments:
+ print "-r--r--r-- 1 user group %d Jan 1 00:00 text" % (len(root_comments))
self._list(self.getroot())
def _list(self, node, path=''):
def getroot(self):
return self.document
+ def get_root_comments(self):
+ return self.collect_text(self.document)
+
def getchildren(self, node):
return node.childNodes
def getroot(self):
return self.document.getroot()
+ def get_root_comments(self):
+ text_accumulator = []
+ for element in self.getroot():
+ if not self.istag(element):
+ text = u"<!--%s-->" % element.text
+ text_accumulator.append(text)
+ return '\n'.join(text_accumulator).encode(default_encoding, "replace")
+
def getlocalname(self, name):
if name.startswith('{'):
name = name.split('}', 1)[1] # Remove XML namespace
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
xml_error('There are no namespaces')
elif path_comp == 'text':
- text = xmlvfs.collect_text(node)
+ if '/' in xml_filename:
+ text = xmlvfs.collect_text(node)
+ else:
+ text = xmlvfs.get_root_comments()
else:
xml_error('Unknown file')