Question: Hello everyone, this is my code. from lxml import etree import glob, os os.chdir(c:XMLFolder) directory = os.getcwd() findText = input(Enter text you would like to

Hello everyone, this is my code.

from lxml import etree import glob, os

os.chdir("c:\XMLFolder") directory = os.getcwd()

findText = input("Enter text you would like to find: ") replacementText = input ("Now enter the text you would like to replace with: ")

for files in glob.glob("*.xml"): file = etree.parse(files) root = file.getroot() for pointers in root.findall("pointers"): for pointer in pointers: pointer = pointers.findall("Pointer") for text in pointer: text = pointer.findall("text").text if findText in text: text.replace(findText, replacementText) print(findText + " has been replaced with " + replacementText)

file.write(files)

I was wondering how I would be able to ge this working.

pointer = pointers.findall("Pointer") for text in pointer: text = pointer.findall("text").text

this is the main problem. I want to find all the Pointer in each pointers and each text in each Pointer. Findall will only work for the top and when I remove the findall for the bottom two, It only searches the first Pointer and not any of the others. Please help.

The language is python.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!