From: Tony Mack Date: Wed, 4 Feb 2009 22:22:29 +0000 (+0000) Subject: added filter method used to remove elements from the dom tree X-Git-Tag: sfa-0.9-0@14641~671 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=f4315e2c477fe7f68af6cc7f466cc721b6ad85cd;p=sfa.git added filter method used to remove elements from the dom tree --- diff --git a/geni/util/rspec.py b/geni/util/rspec.py index 7aaae856..86b50fd9 100644 --- a/geni/util/rspec.py +++ b/geni/util/rspec.py @@ -174,4 +174,26 @@ class Rspec(): return rdict return tempdict + + + def filter(self, tagname, attribute, valuelist, dom = None): + """ + Removes all elements where: + 1. tagname matches the element tag + 2. attribute matches the element attribte + 3. attribute value is in valuelist + """ + + tempdict = {} + if not dom: + dom = self.rootNode + + if dom.localName in [tagname] and dom.attributes.has_key(attribute) and \ + dom.attributes.get(attribute).value in valuelist: + dom.parentNode.removeChild(dom) + + if dom.hasChildNodes(): + for child in dom.childNodes: + self.filter(tagname, attribute, valuelist, child) + # vim:ts=4:expandtab