2

My Code

tree = ET.Element('e')
tree.attrib['u'] = 'F' + str(srh) + '_0'
if procedural_variables:
    pvs = ET.SubElement(tree, 'pvs')
    for procedural_variable in procedural_variables:
        pv = ET.SubElement(pvs, 'pv')

        n = ET.SubElement(pv, 'n')
        n.text = procedural_variable['name']

        v = ET.SubElement(pv, 'v')
        v.text = str(procedural_variable['value'])
ET.dump(tree)

How can I write this tree as some file.xml?

3 Answers 3

3

It seems like you should be able to use ET.tostring. Alternatively, you could use the .write method of the ElementTree class

Sign up to request clarification or add additional context in comments.

Comments

1
file_out=open('output.xml','wb',1000)
ElementTree(file_out).write(tree,encoding="ASCII")
file_out.close()

Comments

0

Just recommend lxml to you. You can google it or click http://lxml.de.

It is pretty easy to use and robust! The API is rather close to that of ET, if not identical.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.