daemon: Minor XML-related cleanup.

This commit is contained in:
tgoff0 2015-02-27 00:06:47 +00:00
parent 1cda303b22
commit 750b6c507d

View file

@ -134,14 +134,23 @@ def getoneelement(dom, name):
if len(e) == 0: if len(e) == 0:
return None return None
return e[0] return e[0]
def iterChildren(dom, nodeType):
'''\
Iterate over all child elements of the given type.
'''
for child in dom.childNodes:
if child.nodeType == nodeType:
yield child
def gettextchild(dom): def gettextchild(dom):
# this could be improved to skip XML comments '''\
child = dom.firstChild Return the text node of the given element.
if child is not None and child.nodeType == Node.TEXT_NODE: '''
for child in iterChildren(dom, Node.TEXT_NODE):
return str(child.nodeValue) return str(child.nodeValue)
return None return None
def getparamssetattrs(dom, param_names, target): def getparamssetattrs(dom, param_names, target):
''' XML helper to get <param name="name" value="value"/> tags and set ''' XML helper to get <param name="name" value="value"/> tags and set
the attribute in the target object. String type is used. Target object the attribute in the target object. String type is used. Target object