1
2
3
4
5
6 import xml.dom.minidom
7
9
10
11 for childnode in dom.childNodes:
12 if childnode.nodeName != "#text" and \
13 childnode.nodeName != "#cdata-section":
14 return True
15 return False
16
18 childsdict = dict()
19 for childnode in dom.childNodes:
20 name = childnode.nodeName.encode(enc)
21 if name == "#text" or name == "#cdata-section":
22
23 continue
24 if haschilds(childnode):
25 v = indexchilds(childnode, enc)
26 else:
27 v = childnode.childNodes[0].nodeValue.encode(enc)
28 if name in childsdict:
29 if isinstance(childsdict[name], dict):
30
31 childsdict[name] = [childsdict[name]]
32 childsdict[name].append(v)
33 else:
34 childsdict[name] = v
35 return childsdict
36
38 dom = xml.dom.minidom.parseString(data.strip())
39 return indexchilds(dom, enc)
40