I helped before with ElementTree,but now i do not touch it.
As i have spend unnecessary time to fix stuff in ElementTree,that eg BS-4 or lxml do right.
if want file overwritten give same name when write
As i have spend unnecessary time to fix stuff in ElementTree,that eg BS-4 or lxml do right.
from bs4 import BeautifulSoup soup = BeautifulSoup(open('binary.xml', encoding='utf-8'), 'xml') result = soup.find('identity') result.string.replace_with('123456') with open('out.xml', 'w', encoding='utf-8') as f: f.write(str(soup))Now get a validat .xml file back where only wanted change is made.
if want file overwritten give same name when write
binary.xml
,that will also work.Output:<?xml version="1.0" encoding="utf-8"?>
<config version="v1">
<chain template="file-system"> // Use the “”file-system” template
<provider id="file-system" type="file-system"> // Modify the “file-system” binary provider
<fileStoreDir>$FILESTORE/binaries</fileStoreDir> // Override the <fileStoreDir> attribute
</fileStoreDir>
<provider>
<identity>123456</identity>
<endpoint>some point.com</endpoint>
</provider>
</provider></chain></config>