1

I'm trying to use the ElementTree library to parse an XML document in python, but the fact that I have an attribute that starts with a lowercase letter is throwing off the parsing. Here is the root node:

<Page xmlns="http://<some url>/AS/VC/Project" Name="Init_Page">

Here is how I have my code implemented:

import xml.etree.ElementTree as ET

tree = ET.parse('C:\Temp\Init_Page.page') #Init_Page.page is an xml file with UTF-8 encoding
root = tree.getroot()
print(root.tag)

#Outputs {http://<some url>/AS/VC/Project}Page

This is obviously not what I want, because I just want it to print just "Page". And because of the way it prints that root tag, if I do root.iter() for a certain tag, nothing prints. When I change the "xmlns" attribute to "Xmlns", however, it prints "Page" for the root tag as it should. And any iteration for child nodes works properly.

I've tried converting the xml to a lowercase string and using fromstring() but I still get the same result.

Is there any way around this? I am using python version 3.7.4.

Any help would be greatly appreciated, as I am fairly new to python!

0 Answers0