xml write node with attributes

The xml functions can now create a node with attributes ( <node
attr="something"/> )
This commit is contained in:
Bryan Schumaker 2010-11-30 23:07:46 -05:00
parent 53027b6006
commit 9ba602318c
1 changed files with 12 additions and 6 deletions

View File

@ -24,21 +24,27 @@ def child(doc):
return list[0]
return None
def add_child(doc, node, name):
def check_type(value):
if value.__class__ == unicode:
return value.encode("utf-8")
return str(value)
def add_child(doc, node, name, attrs = {}):
child = doc.createElement(name)
for attr in attrs:
value = check_type(attrs[attr])
child.setAttribute(attr, value)
node.appendChild(child)
return child
def add_text(doc, node, value):
if value.__class__ == int or value.__class__ == long:
value = str(value)
elif value.__class__ == unicode:
value = value.encode("utf-8")
value = check_type(value)
try:
child = doc.createTextNode( value )
node.appendChild(child)
return value
except:
except Exception, e:
print e
print value, value.__class__
def get_elements(doc, tag):