Error on xpath-ing a DOM with namespaces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Piet

    #1

    Error on xpath-ing a DOM with namespaces

    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.setFeatu re(sax.handler. feature_namespa ces,1)
    parser.setFeatu re(sax.handler. feature_namespa ce_prefixes,1)
    doc = minidom.parse(" fo-file.xml",parse r)
    #everything ok up to here
    outlines = Evaluate("//fox:outline",do c.documentEleme nt)

    I get a RuntimeExceptio n in
    [pythonpath]\Lib\site-packages\_xmlpl us\xpath\Parsed NodeTest.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
    getElementsByTa gNameNS, 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
  • Diez B. Roggisch

    #2
    Re: Error on xpath-ing a DOM with namespaces

    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_do c, processorNss=NS S)
    Evaluate(u'wsdl :description/wsdl:documentat ion', context=ctx)
    """

    Should give you a start.

    --
    Regards,

    Diez B. Roggisch

    Comment

    • Piet

      #3
      Re: Error on xpath-ing a DOM with namespaces

      > NSS = {u'wsdl': u'http://schemas.xmlsoap .org/wsdl/'}[color=blue]
      > #""processorNss " = "namespace bindings to be used by the processor"
      > ctx = Context(wsdl_do c, processorNss=NS S)
      > Evaluate(u'wsdl :description/wsdl:documentat ion', context=ctx)
      > """
      >
      > Should give you a start.[/color]
      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

      Comment

      Working...