I want to change the publicationDateTime="2023-07-31T07:02:59+00:00"
attribute.
My xml is
<?xml version="1.0" encoding="UTF-8" standalone="no"?><Research xmlns="http://www.rixml.org/2005/3/RIXML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" createDateTime="2023-07-31T07:02:16+00:00" language="eng" researchID="GPS-4409687-0" xsi:schemaLocation="http://www.rixml.org/2005/3/RIXML http://www.rixml.org/assets/documents/schemas/RIXML-2_4.xsd">
<Product productID="12345-0">
<Source>
<Organization primaryIndicator="Yes" type="SellSideFirm">
<OrganizationID idType="VendorCode">ABP</OrganizationID>
<OrganizationName nameType="Display">ABCDF</OrganizationName>
</Organization>
</Source>
<Content>
<Title>Novice</Title>
</Content>
<Context external="Yes">
<ProductDetails periodicalIndicator="No" publicationDateTime="2023-07-31T07:02:59+00:00">
<ProductCategory productCategory="Support"/>
</ProductDetails>
</Context>
</Product>
</Research>
This is my code
import os
import xml.etree.ElementTree as ET
import uuid
import time
ET.register_namespace('', "http://www.rixml.org/2005/3/RIXML")
ET.register_namespace('', "http://www.rixml.org/2005/3/RIXML")
OUTPUT_FOLDER = "OUTPUT/"
input_folder = "INPPUT/"
all_files = os.listdir(input_folder)
json_files = {f: f for f in all_files if f.endswith(".xml")}
json_files_keys = list(json_files.keys())
json_files_keys.sort()
for file_name in json_files_keys:
print(file_name)
xmlTree = ET.parse(input_folder+file_name)
root = xmlTree.getroot()
print(root)
print(root.attrib)
for child in root:
print(child.attrib)
pid = '2023-08-04T08:02:59+00:00'
print(pid)
child.set('publicationDateTime', pid)
xmlTree.write(OUTPUT_FOLDER+file_name)
print("written")
I am not able to update the attribute. It gets added at the root level.
Please suggest how to add at the same location.
I am new to Python apology if its very obvious question.