Given the following XML structure
<cmap>
<tableVersion version="0" />
<cmap_format_4 platformID="0" platEncID="3" language="0">
<map code="0x20" name="space" />
<!-- SPACE -->
<!--many, many more characters-->
</cmap_format_4>
<cmap_format_0 platformID="1" platEncID="0" language="0">
<map code="0x0" name=".notdef" />
<!--many, many more characters again-->
</cmap_format_0>
<cmap_format_4 platformID="0" platEncID="3" language="0">
<!--"cmap_format_4" again-->
<map code="0x20" name="space" />
<!-- SPACE -->
<!--more "map" nodes-->
</cmap_format_4>
</cmap>
I'm trying to step through and get a list of node names at the cmap_format_0
level along with all the code
and name
nodes beneath them.
Expected outcome
cmap_format_4
0x0 null
0xd CR
ox20 space
etc...
cmap_format_0
0x0 notdef
0x1 notdeaf
etc...
So far I have
charactersByFontString = "CODE\tCHAR DESC\n"
tree = ET.parse(xmlFile)
root = tree.getroot()
for map in root.iter("map"):
charactersByFontString += map.attrib["code"] + "\t"
charactersByFontString += map.attrib["name"] + "\n"
That's getting all of my codes and names. however I cannot get the name of the c_format_n
.
for child in root:
print child.child
does not work as tableversion
is its first child, is self-closing, and has no children. (Also I'm not sure if stringing together a bunch of child
nodes even works.) child.sibling
got me an error. How can I get these children in the cmap_format_n
format?