Merge branch 'bug_530_add_dm800se_support' into experimental
[enigma2.git] / lib / python / Tools / XMLTools.py
1 import xml.dom.minidom
2
3 def elementsWithTag(el, tag):
4
5         """filters all elements of childNode with the specified function
6         example: nodes = elementsWithTag(childNodes, lambda x: x == "bla")"""
7
8         # fiiixme! (works but isn't nice)
9         if isinstance(tag, str):
10                 s = tag
11                 tag = lambda x: x == s
12                 
13         for x in el:
14                 if x.nodeType != xml.dom.minidom.Element.nodeType:
15                         continue
16                 if tag(x.tagName):
17                         yield x
18
19 def mergeText(nodelist):
20         rc = ""
21         for node in nodelist:
22                 if node.nodeType == node.TEXT_NODE:
23                         rc = rc + node.data
24         return rc
25
26 def stringToXML(text):
27         return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace("'", '&apos;').replace('"', '&quot;')