xpath prob, was Re: Why is there no functional xml?

Peter Otten __peter__ at web.de
Wed Jan 24 04:00:10 EST 2018


Rustom Mody wrote:

> With
> # Read above xml
>>>> with open('soap_response.xml') as f: inp = etree.parse(f)
> # namespace dict
>>>> nsd = {'soap': "http://schemas.xmlsoap.org/soap/envelope/", 'locns':
>>>> "http://example.com/"}
> 
> The following behavior is observed — actual responses elided in the
> interest of brevity
> 
>>>> inp.xpath('//soap:Body', namespaces = nsd)
> finds/reaches the node
> 
>>>> inp.xpath('//locns:blobRetrieveResponse', namespaces = nsd)
> finds
> 
>>>> inp.xpath('//locns:dtCreationDate', namespaces = nsd)
> does not find
> 
>>>> inp.xpath('//dtCreationDate', namespaces = nsd)
> finds
> 
>>>> inp.xpath('//dtCreationDate')
> also finds
> 
> 
> Doesnt this contradict the fact that dtCreationDate is under the locns
> namespace??
> 
> Any explanations??

Can you rewrite that question as a simple self-contained demo, similar to 
the snippet shown under

http://lxml.de/xpathxslt.html#namespaces-and-prefixes

?




More information about the Python-list mailing list