[Add] Rolled my own, much better python xml writing scheme.

This commit is contained in:
Allanis 2013-07-22 10:27:13 +01:00
parent 240869046b
commit 7b7ddae70e
4 changed files with 1184 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -342,7 +342,7 @@ static void update_routine(double dt) {
} }
/** /**
* @brief Renders the game itself (player flying around etc. * @brief Renders the game itself (player flying around etc).
* *
* Blitting order. (layers) * Blitting order. (layers)
* *

View File

@ -139,7 +139,7 @@ def save(xmlfile, data, basetag, tag, has_name=True, do_array=None, do_special=N
xml.appendChild(base) xml.appendChild(base)
fp = open(xmlfile, "w") fp = open(xmlfile, "w")
xml.writexml(fp, "", "", "", "UTF-8") write_proper_xml(fp, xml)
fp.close() fp.close()
xml.unlink() xml.unlink()
@ -217,3 +217,41 @@ def save_Tag(xml, parent, data, do_array=None, do_special=None, do_special2=None
parent.appendChild(node) parent.appendChild(node)
def write_proper_xml(fp, doc):
fp.write('<?xml version="1.0" encoding="UTF-8"?>')
write_xml_node(fp, doc, '')
# Return if it just wrote text.
def write_xml_node(fp, node, indent):
# Special cases.
if node.nodeType == node.TEXT_NODE:
fp.write(node.data)
return True
elif node.nodeType == node.DOCUMENT_NODE:
if node.childNodes:
for n in node.childNodes:
write_xml_node(fp, n, indent)
return False
fp.write('\n%s<%s' % (indent, node.nodeName))
# Process attributes.
attrs = node.attributes
if attrs != None:
for a_name, a_value, in attrs.items():
fp.write(' %s = \"%s\"' % (a_name, a_value))
# Process children.
if node.childNodes:
fp.write(">") # No newline.
for n in node.childNodes:
last = write_xml_node(fp, n, indent+' ')
if last:
fp.write('</%s>' % node.nodeName)
else:
fp.write('\n%s</%s>' % (indent, node.nodeName))
else:
fp.write("/>")
return False