Using xml.xpath question.
Will Stuyvesant
hwlgw at hotmail.com
Fri Jul 11 13:17:10 EDT 2003
> [Paul Boddie]
> ...
> Try this:
> >>> c = xml.xpath.Context.Context(doc)
> >>> c.setNamespaces({"p" : "http://tempuri.org/string"})
> This makes a context and then adds the definition of the prefix for
> the XPath query engine...
> >>> e = xml.xpath.Compile("/p:root/p:child/text()")
> I compile the expression in order to allow the context to be used.
> ... we have to set up a context first to contain those
> definitions.
> >>> e.evaluate(c)
> [<DOM Text node "Hellpppp">]
A very nice and helpful Paul Boddie in action on c.l.p.
But OMFG! Here we see why we need a good *high* level XML library in
the Python Standard Library. The effbot is doing great work with
elementtree at www.effbot.org, but he is doing that all alone. I
think a good high level XML library should have a very high priority
for Python.
It should be a much higher priority for the core Python developers
than the extensions I have seen lately. Booleans, bah! And for
instance, I hate it to make my code unreadable using list
comprehensions and other syntactic sugar; and then later having to
explain it to a C programmer. "Ha!" she says, "You claimed the Python
language reads like pseudocode!". Geez.
More information about the Python-list
mailing list