I want to add a Subelement to a XML file without writing the content to the console.
I am doing the following to add a subelement to a XML file:
import xml.etree.ElementTree as ET
tree=ET.parse('myfile.XML')
root=tree.getroot()
vpn=ET.SubElement(root,'VPN', attrib={'A': 'VPN1', 'B':'0','C': '0.0001', 'D': '0', 'E': '%'})
ET.dump(root)
This does what it should do. But ET.dump()
is writing the XML content to the console which is problematic for bigger XML structures.
In any case the documentation is a bit weird here. Because on the one hand the documentation (see chapter "Building XML documents") says that dump()
should be used to add a sub-element. On the other hand the documentation of the dump()
method indicates that this method should only be used for debugging, which explains why content is printed out to the console.
How can I add a XML Subelement without having the content in the console?