tmonteit
asked on
Python XML issue
I'm having difficulty parsing an xml file and then searching the tree with xpath.
What am I doing wrong here?
2 from xml.etree.ElementTree import ElementTree
3 tree = ElementTree()
4 myTree = tree.parse('myFile.xml')
5 root=myTree.getroot()
6
7 #error1: AttributeError: _ElementInterface instance has no attribute ' > getroot'
8
9 for node in myTree.findall('/*/path'):
10
11 #error2: SyntaxError: cannot use absolute path on element
12
What am I doing wrong here?
2 from xml.etree.ElementTree import ElementTree
3 tree = ElementTree()
4 myTree = tree.parse('myFile.xml')
5 root=myTree.getroot()
6
7 #error1: AttributeError: _ElementInterface instance has no attribute ' > getroot'
8
9 for node in myTree.findall('/*/path'):
10
11 #error2: SyntaxError: cannot use absolute path on element
12
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I do recommend to read the Chapter 12. XML from the "Dive Into Python 3" by Mark Pilgrim. It uses Python 3, but you can apply it also to Python 2.x.
Sorry, I forgot to include the URL: http://diveintopython3.org/xml.html