Read an XML file using ElementTree tree, stripping
default namespace strings from all elements.
This routine is a little bit precarious. Its aim is to strip the
default namespace {uri} from tags so that you don't have to put all that
text into find, findall, findtext, etc... when searching the XML tree
using the ElementTree stuff.
This should work most of the time. That is, when there is only one
default namespace declared, in the root of the XML tree, then it will be
just fine. In other instances, where the default namespace changes
throughout the XML document, the behavior can be unexpected.
Actually, the behavior of this function isn't unexpected. It will
work just fine. It's the behaviour of anything using it that will be
unexpected. If you change default namespaces, and you have tags that
have duplicate local portions that are differentiated by the namespace,
then they will all be retrieved by the find... calls. This may not be
what you want. Luckily, in the limited world that this routine operates
in (so far), this isn't a problem. GPX, TCX, and SABX files all have one
default namespace, declared in the root element. Let's hope.
- Parameters:
source (string or open file handle) - XML file to read
- Returns:
Element
- tree root
Element (NOT an
ElementTree object)
|