Mercurial > hg > MetaDataProvider
changeset 17:ba617e755c56
mostly finished attributions and copyright
author | casties |
---|---|
date | Tue, 02 Aug 2011 18:28:39 +0200 |
parents | 5d41c350dd2b |
children | 611b6df70840 |
files | MetaData.py MetaDataFolder.py |
diffstat | 2 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/MetaData.py Tue Aug 02 13:38:01 2011 +0200 +++ b/MetaData.py Tue Aug 02 18:28:39 2011 +0200 @@ -122,6 +122,10 @@ if attr: data['@attr'] = attr + # put text in @text + if elem.text: + data['@text'] = elem.text + for e in elem: # put all child elements in data if normalizeNames: @@ -131,7 +135,7 @@ key = e.tag if recursive > 0: - # more recursive - call _getData on elements + # more recursive - call _getData on element val = self._getData(e, recursive=recursive-1, normalizeNames=normalizeNames, all=all, allText=allText) else: val = getText(e, recursive=allText) @@ -162,6 +166,9 @@ return None elem = self.getSubDom(path=path, dom=dom, all=all) + if elem is None: + return None + if all: # subdom is list - return list data = []
--- a/MetaDataFolder.py Tue Aug 02 13:38:01 2011 +0200 +++ b/MetaDataFolder.py Tue Aug 02 18:28:39 2011 +0200 @@ -131,23 +131,23 @@ obj = self.restrictedTraverse(xmlpath, None) return obj - def getXmlPathData(self, xmlpath, path=None, dom=None, allText=False, all=False): + def getXmlPathData(self, xmlpath, path=None, dom=None, recursive=0, all=False, allText=False): """returns contents of element at xmlpath as dict""" logging.error("getXmlPathData(%s)"%xmlpath) mdObj = self.getXmlPathObj(xmlpath) if mdObj is not None: - return mdObj.getData(path=path, dom=dom, allText=allText, all=all) + return mdObj.getData(path=path, dom=dom, recursive=recursive, all=all, allText=allText) else: logging.error("getXmlPathData: MetaData element at '%s' not found!"%xmlpath) return None - def getXmlPathFormatted(self, xmlpath, template, path=None, dom=None, data=None, allFields=False, allText=False, all=False): + def getXmlPathFormatted(self, xmlpath, template, path=None, dom=None, data=None, allFields=False, recursive=0, all=False, allText=False): """returns contents of element at xmlpath as dict""" logging.error("getXmlPathFormatted(xmlpath=%s, template=%s)"%(xmlpath,template)) mdObj = self.getXmlPathObj(xmlpath) if mdObj is not None: if data is None: - data = mdObj.getData(path=path, dom=dom, allText=allText, all=all) + data = mdObj.getData(path=path, dom=dom, recursive=recursive, all=all, allText=allText) if data is None: return '' @@ -188,9 +188,9 @@ """returns formatted contents of access tag""" return self.getXmlPathFormatted('resource/meta/access-conditions/attribution', template, path=path, dom=dom, data=data, all=all) - def getCopyrightData(self, path=None, dom=None, all=True): + def getCopyrightData(self, path=None, dom=None, recursive=1, all=True): """returns contents of copyright tag as dict""" - return self.getXmlPathData('resource/meta/access-conditions/copyright', path=path, dom=dom, allText=True, all=all) + return self.getXmlPathData('resource/meta/access-conditions/copyright', path=path, dom=dom, recursive=recursive, all=all) def getCopyrightFormatted(self, template, path=None, dom=None, data=None, all=True): """returns formatted contents of access tag"""