Re:Python module that makes working with XML feel like worki...
by toyg on Friday August 23, 2013 @07:28AM
(#6262818)
Correctly handling namespaced QNames is a requirement, not a bug. It makes things awkward at times, but that's a job for lib writers to provide decent interfaces.
I haven't used LXML in a while, but ElementTree, for example, forces you to use the QName in XPath expressions, which is technically correct but a huge pain; it would be nice if there was a ScrewNamespace option that would allow "simple" searches, although this might blow up in your face one day (when two namespaces define the same element name, and your xpath search brings up elements you didn't really want).
Re:Python module that makes working with XML feel like worki...
by raverbashing on Friday August 23, 2013 @09:59AM
(#6263628)
Actually the short name worked for the searches, the problem was reading element names from a subtree
It's not as much as dodging the requirements but rather an inconsistency in the API.
Re:Python module that makes working with XML feel like worki...
by TimSAstro on Friday August 23, 2013 @09:13AM
(#6263257)
I also found the namespacing to be a bit weird, and it took quite a while to grok the documentation. In case anyone wants a working example, I implemented a wrapper to drop the namespacing (resulting in simple objectify attribute access) for one particular XML schema here:
https://github.com/timstaley/voevent-parse/blob/master/voepa...
Re:Python module that makes working with XML feel like worki...
by georgebashi on Friday August 23, 2013 @07:29AM
(#6262823)
That's the "node-name", i.e. the fully qualified name of the tag in its namespace. You probably wanted to ask for the local-name, which in your example would just be "index". Not sure how to with LXML, but it's a common mistake people make when dealing with XML.
But usually, yes, LXML is "good" meaning it's the least worse way of dealing with XML
Also, it has some idiosyncrasies, like insisting on adding the namespace on tag names, so you end with something like {http://example.com/your.xlsd}.index (I don't remember it exactly and I don't have an example here with me)