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