-1
I have several XML files inside a folder that is called FILES and it is local in Windows.
All XML files follow the same structure as below:
<catalog>
<product description="Cardigan Sweater" product_image="cardigan.jpg">
<catalog_item gender="Men's">
***<item_number>QWZ5671</item_number>***
<price>39.95</price>
<size description="Medium">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
</size>
<size description="Large">
I would like to remove from this XML the information:
<price>39.95</price>
That is, the 39.95 between <price>
and </price>
And create another file in CSV or TXT format. This for all files in this folder in automated way.
I tried to create the following code:
search = 'print'
def check():
datafile = open('C:\\ARQUIVOS\example.xml')
for line in datafile:
if search in line:
found = </price>
print(line)
break
else:
found = price
return found
check()
I couldn’t get past it, and I don’t know how to finish it. Could someone please help me? Remembering that they are for various xml inside a folder!
There will only be one tag
<price>
per file or each file may have more of that tag? And what is the output file structure?– Augusto Vasques