Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
xml replacement with python
#1
Hello
I try to use python to replace part of the xml file without override the rest of the file,
the code doesn't show any error but it is not replacing the code
My idea is find the tag <AudioCodeco> and then, I will change the first line which is:
<Codec Name="PCMA" Enabled="True"/>
by
<Codec Name="PCMA" Enabled="False"/>

As you could notice, I want to change True by False

If you have a better idea, I will appreciate your orientation.

This is my code

# import element tree
import xml.etree.ElementTree as ET 


#import xml file
tree = ET.parse(r'C:\ProgramData\Genetec Sipelia\SipServer\SipServer.config')
root = tree.getroot()
#replace bounding box with new coordinates

elem = tree.findall('AudioCodecs')

for elem1 in elem:
    elem1.txt = 'Codec Name="PCMA" Enabled="False"'
 
and this is my xml

<?xml version="1.0"?>
<!-- WARNING: Those configuration represent the the default values for Sipelia SIP Server -->
<!-- WARNING: It is very recommended to make a backup of this file before doing any changes -->
<SipeliaSipServer>
<Configuration Version="2.0.7">
<!-- Values must be between 0 and 65535 -->
<MinimumPortRange Value="20000"/>
<MaximumPortRange Value="20500"/>
<!-- Value is in seconds. Minimum value is 40 -->
<TrunkStateTimeout Value="60"/>
<!-- Value is in seconds. Minimum value is 0 -->
<DeviceRegistrationMargin Value="60"/>
<!-- Value is enabled or disabled. Used to resolve invalid SIP contact header fields. -->
<InvalidContactFieldResolution Enabled="False" />
<!-- Sipelia SIP Server Audio and Video codecs -->
<!-- WARNING: Edit only the 'Enabled' attribute value -->
<Codecs>
<VideoCodecs>
<Codec Name="H263-1998" Enabled="True"/>
<Codec Name="H264" Enabled="True" KeyframeGenerationInterval="4"/> <!-- KeyframeGenerationInterval: When transcoding to H264 this value will be used to generate the keyframes. The default value for K-frame is 4s. -->
<Codec Name="H263" Enabled="True"/>
</VideoCodecs>
<AudioCodecs>
<Codec Name="PCMA" Enabled="True"/>
<Codec Name="PCMU" Enabled="True"/>
<Codec Name="telephone-event" Enabled="True"/>
<Codec Name="iLBC" Enabled="True"/>
<Codec Name="G722" Enabled="True"/>
<Codec Name="GSM" Enabled="True"/>
<Codec Name="SPEEX_Narrowband" Enabled="False"/>
<Codec Name="SPEEX_Wideband" Enabled="True"/>
<Codec Name="SPEEX_Ultrawideband" Enabled="True"/>
<Codec Name="L16" Enabled="False"/>
<Codec Name="L16_44_1" Enabled="True"/>
<Codec Name="G728" Enabled="False"/>
<Codec Name="G723" Enabled="False"/>
<Codec Name="G726-16" Enabled="True"/>
<Codec Name="G726-24" Enabled="False"/>
<Codec Name="G726-32" Enabled="False"/>
<Codec Name="G726-40" Enabled="False"/>
<Codec Name="G729" Enabled="False"/>
</AudioCodecs>
</Codecs>
<!-- The default method name is 'None' -->
<NatTraversalMethod Value="None"/>
</Configuration>
</SipeliaSipServer>



Regards,

Jose
Reply


Messages In This Thread
xml replacement with python - by josesalazmit - Feb-23-2019, 03:48 AM
RE: xml replacement with python - by stullis - Feb-23-2019, 04:57 AM
RE: xml replacement with python - by josesalazmit - Feb-24-2019, 06:06 PM
RE: xml replacement with python - by stullis - Feb-24-2019, 07:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  If I need to do regex replacement 27000 times, how to shorten it? tatahuft 4 974 Dec-26-2024, 01:51 AM
Last Post: deanhystad
  replacement for fpformat.extract GbSig1998 4 1,490 Apr-12-2024, 06:15 PM
Last Post: deanhystad
  String replacement in DB WJSwan 0 1,290 Dec-28-2022, 05:31 AM
Last Post: WJSwan
Exclamation IndexError: Replacement index 2 out of range for positional args tuple - help? MrKnd94 2 14,346 Oct-14-2022, 09:57 PM
Last Post: MrKnd94
  Extract the largest value from a group without replacement (beginner) preliator 1 2,731 Aug-12-2020, 01:56 PM
Last Post: DPaul
  Simple automated SoapAPI Call with single variable replacement from csv asaxty 1 2,915 Jun-30-2020, 06:38 PM
Last Post: asaxty
  line replacement help mdalireza 8 5,045 Nov-11-2019, 12:54 PM
Last Post: mdalireza
  Best replacement for pyzmail in lines 15 and 16 Pedroski55 0 3,200 Nov-03-2018, 06:12 AM
Last Post: Pedroski55
  Is pathlib a viable replacement for os.path? j.crater 4 11,897 Jan-13-2018, 09:49 AM
Last Post: Gribouillis
  Using python for text replacement omar 1 4,599 Dec-22-2016, 01:36 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020