diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-01-04 16:50:22 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-01-04 16:50:22 -0500 |
commit | 97a03c4d92b71b222cbe123d8517239043af6e50 (patch) | |
tree | 7abef1ceec337a182fe1c899095a38896073db57 | |
parent | 78c2fc00029c2319787d6a7535e9b216fe2a9b96 (diff) |
Updated node.py from mso-dumper.
-rw-r--r-- | source/node.py | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/source/node.py b/source/node.py index e14f894..35158dc 100644 --- a/source/node.py +++ b/source/node.py @@ -1,9 +1,17 @@ +# This file (node.py) gets copied in several of my projects. Find out a way +# to avoid making duplicate copies in each of my projects. + import sys class NodeType: + # unknown node type. Unknown = 0 - Root = 1 + # the document root - typically has only one child element, but it can + # have multiple children. + Root = 1 + # node that has name and attributes, and may have child nodes. Element = 2 + # node that only has textural content. Content = 3 class NodeBase: @@ -112,11 +120,18 @@ def encodeString (sin): return sout -nodesToSkip = { -# 'paragraph': 1, - 'comment': 1, - 'history': 1 -} +def convertAttrValue (val): + if type(val) == type(True): + if val: + val = "true" + else: + val = "false" + elif type(val) == type(0): + val = "%d"%val + elif type(val) == type(0.0): + val = "%g"%val + + return val def prettyPrint (fd, node): printNode(fd, node, 0) @@ -138,8 +153,13 @@ def printNode (fd, node, level): keys = node.attrs.keys() keys.sort() for key in keys: - line += " " + key + '="' + encodeString(node.attrs[key]) + '"' - if hasChildren:# and not nodesToSkip.has_key(node.name): + val = node.attrs[key] + if val == None: + continue + val = convertAttrValue(val) + line += " " + key + '="' + encodeString(val) + '"' + + if hasChildren: line = "<%s>\n"%line fd.write (indent + line) for child in node.getChildNodes(): |