I want to use a java script for my bachelor thesis that uses XML files as input. Since most of my other work was done in python, i want to create a bridge between the two programs by opening the XML file in python and changing some class attribute values to previously calculated results from my python code. Then i want to write the XML file in python so the java script can use it as input. I have not had any issues editing the values using xml.etree.ElementTree but after writing the file the values are changed but the header and DOCType are completly gone. Is there any way to add or just not remove them in the first place using python? I have searched the internet but have not been able to find a good solution yet. I am pretty new to XMLs and Java unfortunately.
Im posting here for the first time, so im sorry if i forgot any necessary information
This is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE uam SYSTEM "src/main/resources/dtd/uam.dtd">
<uam>
<stations>
<station id="MUC_OD_2_1" name="Location 948" preflighttime="0" postflighttime="0" defaultwaittime="0" link="uam_sl-uam_st_MUC_OD_2_1_ga-uam_st_MUC_OD_2_1_fa" />
<station id="MUC_OD_2_2" name="Location 1000" preflighttime="0" postflighttime="0" defaultwaittime="0" link="uam_sl-uam_st_MUC_OD_2_2_ga-uam_st_MUC_OD_2_2_fa" />
</stations>
<vehicleTypes>
<vehicleType id="MC" range="99999" capacity="6" cruisespeed="60.0" verticalspeed="10.0" boardingtime="0" deboardingtime="0" turnaroundtime="0" />
</vehicleTypes>
<vehicles>
<vehicle id="uam_vh_MUC_OD_2_1-0" type="MC" initialstation="MUC_OD_2_1" starttime="00:00:00" endtime="30:00:00" />
<vehicle id="uam_vh_MUC_OD_2_2-0" type="MC" initialstation="MUC_OD_2_2" starttime="00:00:00" endtime="30:00:00" />
</vehicles>
</uam>
This is my Python code:
import xml.etree.ElementTree as ET
from dictionary import getDict
from Dict_manufacturers import getDict_manu
def VehiclesInput(UAMtype):
tree = ET.parse('muc_network_s_od_2_v_uam_vehicles.xml')
root = tree.getroot()
if ...(editing values)
tree.write('muc_network_s_od_2_v_uam_vehicles.xml', encoding = "UTF-8", xml_declaration = True)
return