Home > other >  Can't Access "Data" in the XML Data structure: <Name Attributes> Data </Name
Can't Access "Data" in the XML Data structure: <Name Attributes> Data </Name

Time:05-25

i need to Access the "Data" in the following XML Data structure:

<Name Attributes> Data </Name>

With the normal Python Parsing .attrib i can only Access the "Attributes" but i need the "Data".

Do you know what this Data structure means and how i can Access the "Data" with Python.

Thank you!

CodePudding user response:

According to your example, it should be name.text or you want to assign new value for this name.text = "new Data"

Example:

import xml.etree.ElementTree as ET
tree = ET.parse("some-random-file")
parent = tree.getroot()

name = parent.find(".//name")
name.text = "new Data"

Reference

  • Related