Just to be clear, you are talking about namespace prefixes here, not
namespaces per se.
Ideally, an API allows you register a namespace prefix, just as you do
in an XML document. Not sure if ET forces you to write custom code to
do this.
But this again raises the question: why not just use dedicated objects
for access? Then you know precisely how to get what you want. Just
iterate through the XML document, load it into objects, and then do
your work.
Here’s an example from my Ruby code (using REXML; which, BTW, doesn’t
handle namespaces correctly!):
# creates a csl metadata object from csl file
def info
config = {}
csl.elements.each("/citationstyle/info/*") do |e|
if e.nil? then content = nil
else content = e.text
end
config[e.name] = content
end
CSLInfo.new(title=config["title"],
short_title=config["title-short"],
date_created=config["dateCreated"])
end
Also, see:
<O'Reilly Media - Technology and Business Training
thoughts_on_xpath_xml_python.html>
http://uche.ogbuji.net/tech/4suite/amara/
http://www.xml.com/pub/a/2005/01/19/amara.html
An example:On Aug 10, 2006, at 5:40 AM, Johan Kool wrote:
What I feel is more of a show-stopper is this behaviour of
ElementTree: Simple XML Processing With elementtree
I.e. it changes the names of the namespaces, and although this is
officially allowed in XML, I’d rather not have that happen when I
merge the results into the incoming XML document.
===
from amara import binderytools
csl = binderytools.bind_file(‘apa.csl’)
print csl.style.info.title
American Psychological Association
===
Nice, eh?
It also has xpath support, and namespace prefix binding.
I didn’t quite work out how to iterate over child elements though.
Bruce