[Tutor] xml parsing from xml
Neil D. Cerutti
neilc at norwich.edu
Wed May 7 22:32:55 CEST 2014
On 5/7/2014 3:49 PM, Stefan Behnel wrote:> Neil D. Cerutti, 07.05.2014
20:04:
>> In my own personal case, I partly prefer xml.sax simply because it
ignores
>> namespaces, a nice benefit in my cases. I wish I could make
ElementTree do
>> that.
>
> The downside of namespace unaware parsing is that you never know what you
> get. It works for some input, but it may also just fail arbitrarily, for
> equally valid input.
>
> One cool thing about ET is that it makes namespace aware processing
easy by
> using fully qualified tag names (one string says it all). Most other XML
> tools (including SAX) require some annoying prefix mapping setup that you
> have to carry around in order to tell the processor that you are really
> talking about the thing that it's showing to you.
It's a minor frustration. I don't want to:
index = xml_obj.find(
"{http://www.ed.gov/FSA/COD/2011/v3.0e}School/"
"{http://www.ed.gov/FSA/COD/2011/v3.0e}Student/"
"{http://www.ed.gov/FSA/COD/2011/v3.0e}Index")
ElementTree doesn't obviously make it easier.
I work around it by wrapping the find and findall functions. There's
probably a class I could inherit instead. Or maybe there's an even
better approach.
--
Neil Cerutti
More information about the Tutor
mailing list