0

Using Python 3.x I need to read / modify the text highlighted in the picture below:

The code I have developped crawls thru the XML file and it displays eg: the 7F7F7F and the hu-HU correctly, but not the highlighted text. (which makes sense to me, because I am certainly missing something)

How can I read / modify that part of the XML? Is there any trivial way to do it, or do I need to use my recursive algorithm? (I am completely new to python as well as to XML)

import xml.etree.ElementTree as ET

tree = ET.parse('c:\\temp\\document.xml')
root = tree.getroot()

def myRecursion(param1):
    for child in param1:
        myString = str(child.attrib)
        print(child.items())
        myRecursion(child)

myRecursion(root)`
Istvanb
  • 392
  • 2
  • 6
  • 19
  • Its not a duplicate as the line in my XML has no tag(s) / attrib(s). The question referred as the same will not solve my problem. – Istvanb Oct 20 '17 at 14:09
  • To access the 'MIU-342' part, use `param1.text`. Your recursion function should also print the current element - and then only call `myRecursion(child)` in the for loop. – Kargathia Oct 20 '17 at 14:14
  • Wonderful, now I am able to find the text! Thanks. Can you enlight me how to change that text in the XML? – Istvanb Oct 20 '17 at 14:20
  • That's 100% a duplicate question. – Kargathia Oct 20 '17 at 14:54

0 Answers0