# coding: utf-8
import xml.dom.minidom as m
d = m.parse(open('plan.svg'))
[_.nodeType for _ in d.childNodes]
R = {y:x for x,y in {'ATTRIBUTE_NODE': 2,
'CDATA_SECTION_NODE': 4,
'COMMENT_NODE': 8,
'DOCUMENT_FRAGMENT_NODE': 11,
'DOCUMENT_NODE': 9,
'DOCUMENT_TYPE_NODE': 10,
'ELEMENT_NODE': 1,
'ENTITY_NODE': 6,
'ENTITY_REFERENCE_NODE': 5,
'NOTATION_NODE': 12,
'PROCESSING_INSTRUCTION_NODE': 7,
'TEXT_NODE': 3}.items()}
R
[R.get(_.nodeType) for _ in d.childNodes]
dirdesc(d)
sorted(dirdesc(d))
dirdesc(d)
[R.get(_.nodeType) for _ in d.childNodes]
root = d.childNodes[1]
root.childNodes.length
groupings((R[x.nodeType],x) for x in root.childNodes)
G = groupings((R[x.nodeType],x) for x in root.childNodes)
G.keys()
lmap(len, G.values())
S = set(x.nodeValue.strip() for x in G['TEXT_NODE'])
len(S)
S
set(x.nodeName.strip() for x in G['ELEMENT_NODE'])
Counter(x.nodeName.strip() for x in G['ELEMENT_NODE'])