xml write node with attributes
The xml functions can now create a node with attributes ( <node attr="something"/> )
This commit is contained in:
parent
53027b6006
commit
9ba602318c
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue