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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started