Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Error on xpath-ing a DOM with namespaces

Reply
Thread Tools

Error on xpath-ing a DOM with namespaces

 
 
Piet
Guest
Posts: n/a
 
      03-06-2005
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_pr efixes,1)
doc = minidom.parse("fo-file.xml",parser)
#everything ok up to here
outlines = Evaluate("//foxutline",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
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      03-06-2005
From http://uche.ogbuji.net/tech/akara/no...01/basic-xpath

"""
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.

--
Regards,

Diez B. Roggisch
 
Reply With Quote
 
 
 
 
Piet
Guest
Posts: n/a
 
      03-09-2005
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MS IE DOM DOM2 and Namespaces Aaron Gray Javascript 1 12-22-2006 01:16 PM
Setting namespaces in DOM Rogan Dawes Java 0 09-30-2005 03:21 PM
Clarification on XML parsing & namespaces (xml.dom.minidom) Greg Wogan-Browne Python 1 01-28-2005 03:19 AM
Problem parsing namespaces with xml.dom.minidom Mike McGavin Python 5 01-19-2005 02:05 AM
Difference between pure DOM and JAXP over DOM ?? Thorsten Meininger Java 0 07-28-2004 08:51 AM



Advertisments