Hello I am a noob in XML and Python. I am trying to do this for my MSc project about a network simulation and need some help.... I want to change the values shown below:
<num_crash_failures>1</num_crash_failures>
<crash_failure_entry>
<freeze_at_slot>0</freeze_at_slot>
<freeze_duration>0</freeze_duration>
<freeze_num>0</freeze_num>
<freeze_repeat_rate>0</freeze_repeat_rate>
</crash_failure_entry>
The code goes like this. Basically there are some parameters for every node in the system and the nodes goes like node0 node1 and every parameter name is same. I managed to change a single value like this:
# create a backup of original file
new_file_name = 'temp/1_cluster_TTP.dat.xml'
old_file_name = new_file_name + "backup"
os.rename(new_file_name, old_file_name)
# change text value of element
doc = parse(old_file_name)
node = doc.getElementsByTagName('num_clusters')
node[0].firstChild.nodeValue = '1'
# persist changes to new file
xml_file = open(new_file_name, "w")
doc.writexml(xml_file, encoding="utf-8")
xml_file.close()
But the problem is "num_clusters" is exists in only one place. The real parameters I want to change is in every nodes' parameter and the names are also the same. How can I modify this code to reach and change every values that I mentioned above? Any help is appreciated. Thank you.
<Node>
<Name>Node_0</Name>
<coldstart_flag>1</coldstart_flag>
<max_coldstart_frames>1</max_coldstart_frames>
<CIA>1</CIA>
<time_master_node>0</time_master_node>
<gateway_connection>0</gateway_connection>
<sys_drift>-0.000250</sys_drift>
<stoch_drift>0.000000</stoch_drift>
<logging_disabled>0</logging_disabled>
<Failures>
<crash_failures_enabled>1</crash_failures_enabled>
<Crash>
<num_crash_failures>1</num_crash_failures>
<crash_failure_entry>
<freeze_at_slot>0</freeze_at_slot>
<freeze_duration>0</freeze_duration>
<freeze_num>0</freeze_num>
<freeze_repeat_rate>0</freeze_repeat_rate>
</crash_failure_entry>
</Crash>
<transmission_failures_enabled>0</transmission_failures_enabled>
<Transmission>
<num_transmission_failures>1</num_transmission_failures>
<transmission_failure_entry>
<faulty_msg_in_round>0</faulty_msg_in_round>
<faulty_msg_num>0</faulty_msg_num>
<faulty_msg_repeat_rate>0</faulty_msg_repeat_rate>
</transmission_failure_entry>
</Transmission>
<clock_state_failures_enabled>0</clock_state_failures_enabled>
<Clock_state>
<num_clock_state_failures>1</num_clock_state_failures>
<clock_state_failure_entry>
<change_clock_state_at_slot>0</change_clock_state_at_slot>
<change_clock_state_ticks>0</change_clock_state_ticks>
<change_clock_state_num>0</change_clock_state_num>
<change_clock_state_repeat_rate>0</change_clock_state_repeat_rate>
</clock_state_failure_entry>
</Clock_state>
<clock_rate_failures_enabled>0</clock_rate_failures_enabled>
<Clock_rate>
<num_clock_rate_failures>1</num_clock_rate_failures>
<clock_rate_failure_entry>
<change_drift_at_slot>0</change_drift_at_slot>
<change_drift_by>0.000000</change_drift_by>
<change_drift_num>0</change_drift_num>
<change_drift_repeat_rate>0</change_drift_repeat_rate>
</clock_rate_failure_entry>
</Clock_rate>
</Failures>
</Node>
<Node>
<Name>Node_1</Name>
<coldstart_flag>0</coldstart_flag>
<max_coldstart_frames>1</max_coldstart_frames>
<CIA>1</CIA>
<time_master_node>0</time_master_node>
<gateway_connection>0</gateway_connection>
<sys_drift>-0.000150</sys_drift>
<stoch_drift>0.000000</stoch_drift>
<logging_disabled>0</logging_disabled>
<Failures>
<crash_failures_enabled>0</crash_failures_enabled>
<Crash>
<num_crash_failures>1</num_crash_failures>
<crash_failure_entry>
<freeze_at_slot>0</freeze_at_slot>
<freeze_duration>0</freeze_duration>
<freeze_num>0</freeze_num>
<freeze_repeat_rate>0</freeze_repeat_rate>
</crash_failure_entry>
</Crash>
<transmission_failures_enabled>0</transmission_failures_enabled>
<Transmission>
<num_transmission_failures>1</num_transmission_failures>
<transmission_failure_entry>
<faulty_msg_in_round>0</faulty_msg_in_round>
<faulty_msg_num>0</faulty_msg_num>
<faulty_msg_repeat_rate>0</faulty_msg_repeat_rate>
</transmission_failure_entry>
</Transmission>
<clock_state_failures_enabled>0</clock_state_failures_enabled>
<Clock_state>
<num_clock_state_failures>1</num_clock_state_failures>
<clock_state_failure_entry>
<change_clock_state_at_slot>0</change_clock_state_at_slot>
<change_clock_state_ticks>0</change_clock_state_ticks>
<change_clock_state_num>0</change_clock_state_num>
<change_clock_state_repeat_rate>0</change_clock_state_repeat_rate>
</clock_state_failure_entry>
</Clock_state>
<clock_rate_failures_enabled>0</clock_rate_failures_enabled>
<Clock_rate>
<num_clock_rate_failures>1</num_clock_rate_failures>
<clock_rate_failure_entry>
<change_drift_at_slot>0</change_drift_at_slot>
<change_drift_by>0.000000</change_drift_by>
<change_drift_num>0</change_drift_num>
<change_drift_repeat_rate>0</change_drift_repeat_rate>
</clock_rate_failure_entry>
</Clock_rate>
</Failures>