В основном я пытаюсь импортировать XML-файл в Python и удалить все данные, для которых entityNo равен 1111111111.
Вот текстовая копия XML-данных:
<memberBasedResearchDataImport>
<surveyDescr>D520</surveyDescr>
<surveyType>MEG</surveyType>
<surveyRequester>1543588274</surveyRequester>
<product>DISC</product>
<externalRef>PKG_RPTA88425_4</externalRef>
<DateTimeCreated>20191019 05:10:33</DateTimeCreated>
<identifierSettings>
<identifierType id="1" database="DARE" schema="dp_da_crm" table="ratings" column="object_cd" columnType="number"></identifierType>
<identifierType id="2" database="DARE" schema="dp_da_ent" table="entity" column="full_name" columnType="varchar2"></identifierType>
<identifierType id="3" database="dual" schema="dual" table="dual" column="dual" columnType="varchar2"></identifierType>
</identifierSettings>
<row id="1" entityNo="1054354679" entityRole="KP" policyNo="0" agentEntityNo="1103354880">
<templateValue name="INTERACTION_DAY" value="Friday"></templateValue>
<identifierType id="1" value="671535634817"></identifierType>
<identifierType id="2" value="CUSTOMER SERVICES: SALES"></identifierType>
</row>
<row id="2" entityNo="1111111111" entityRole="AP" policyNo="0" agentEntityNo="11351512571">
<templateValue name="INTERACTION_DAY" value="Friday"></templateValue>
<identifierType id="1" value="6715354549"></identifierType>
<identifierType id="2" value="CUSTOMER SERVICES: ADMIN"></identifierType>
</row>
<row id="3" entityNo="100000571" entityRole="LP" policyNo="0" agentEntityNo="112355274">
<templateValue name="INTERACTION_DAY" value="Friday"></templateValue>
<identifierType id="1" value="671546864"></identifierType>
<identifierType id="2" value="CUSTOMER SERVICES: SALES"></identifierType>
</row>
<row id="4" entityNo="1111111111" entityRole="HP" policyNo="0" agentEntityNo="112456466850"><templateValue name="INTERACTION_DAY" value="Friday"></templateValue>
<identifierType id="1" value="6793437110"></identifierType>
<identifierType id="2" value="CUSTOMER SERVICES: RETURNS"></identifierType>
</row>
</memberBasedResearchDataImport>
До сих пор я пробовал несколько решений, которые я нашел в Интернете, но безуспешно. Код ниже - это то, что я нашел в другом посте, но он не удаляет данные, которые мне нужны для удаления. Мой код ниже, и любая помощь будет принята с благодарностью. Опять же, мне нужно удалить данные, где entityNo = 1111111111, а затем экспортировать данные в формате XML.
from xml.etree.ElementTree import ElementTree
path_to_xml_file = "C:\Users\username\Documents\Data_File.xml"
tree = ElementTree()
tree.parse(path_to_xml_file)
foos = tree.findall("entityNo")
for foo in foos:
bars = foo.find("1111111111")
for bar in bars:
foo.remove(bar)
tree.write("C:\Users\username\Documents\Data_File.xml")