Hello
I am using the cElementTree
library to parse XML files in Python.
Everything is working fine
But I would like to provide full error messages for the user when a value in the XML is not correct.
For example, let's suppose I have the following XML:
<A name="xxxx" href="yyyy"/>
and want to tell the user if the href
attribute doesn't exist or have a value that is not in a given list.
For the moment, I have something like
if elem.get("ref") not in myList:
raise XMLException( elem, "the 'href' attribute is not valid or does not exist")
where my exception is caught somewhere.
But, in addition, I would like to display the line number of the XML element in the file. It seems that the cElementTree
doesn't store any information about the line numbers of the XML elements of the tree... :-(
Question: Is there an equivalent XML library that is able to do that? Or a way to have access to the position of an XML element in the XML file ?
Thanks