Error on xpath-ing a DOM with namespaces

P

Piet

Hello,
Via Xpath, I want to access nodes which have a namespace prefix. THe
document at hand is an Xsl-FO document. I tried the following:
from xml.dom import minidom
from xml.xpath import Evaluate
from xml import sax
parser = sax.make_parser()
parser.setFeature(sax.handler.feature_namespaces,1)
parser.setFeature(sax.handler.feature_namespace_prefixes,1)
doc = minidom.parse("fo-file.xml",parser)
#everything ok up to here
outlines = Evaluate("//fox:eek:utline",doc.documentElement)

I get a RuntimeException in
[pythonpath]\Lib\site-packages\_xmlplus\xpath\ParsedNodeTest.py, line
168 because of an undefined namespace "fox"
In the xml document, the namespace "fox" is defined, e.g. it has been
assigned an URL via xmlns:fox. I have installed pyxml 0.83 and 4suite
1.0a3.
Since I never had to deal with namespaces before, I have no real idea
what to try next. I don't like to use the DOM functions like
getElementsByTagNameNS, because xpath is more flexible. Is this error
above caused by the employed xml tools, or have I missed something
basic about xpath and namespaces in general?
Many thanks in advance
Piet
 
P

Piet

NSS = {u'wsdl': u'http://schemas.xmlsoap.org/wsdl/'}
#""processorNss" = "namespace bindings to be used by the processor"
ctx = Context(wsdl_doc, processorNss=NSS)
Evaluate(u'wsdl:description/wsdl:documentation', context=ctx)
"""

Should give you a start.
Thanks a lot. I found a solution for my problem and lots of food for
thought for improving my XML handling in general.
Best regards
Piet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top