Packers_F 3 Bumpstop_F<" /> Packers_F 3 Bumpstop_F<" /> Packers_F 3 Bumpstop_F<"/>

append new values in xml with python and minidom

55 views Asked by At

i have the following xml

<?xml version="1.0"?>
<Constants>
<Constant>
<Name>Packers_F</Name>
<Value>3</Value>
</Constant>
<Constant>
<Name>Bumpstop_F</Name>
<Value>30</Value>
</Constant>
</Constants>

I would like to add a new object

<Constant>
<Name>MYNEWNAME</Name>
<Value>1234</Value>
</Constant>

What is the correct implementation with minidom ? I'm trying to bend my head around it but i'm struggling quite a bit.... I have a script that reads the constants:

document = parse(xml_file.name)
contants = document.getElementsByTagName("Constant")
for constant in contants:
    temp_name = constant.getElementsByTagName('Name')[0]
    temp_value = constant.getElementsByTagName('Value')[0]
    print(getNodeText(temp_name),':',getNodeText(temp_value))

But how the addChild or addTextNode should be used is really not clear to me.

Thanks.

0

There are 0 answers