Error on xpath-ing a DOM with namespaces

Discussion in 'Python' started by Piet, Mar 6, 2005.

  1. Piet

    Piet Guest

    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
     
    Piet, Mar 6, 2005
    #1
    1. Advertising

  2. From http://uche.ogbuji.net/tech/akara/nodes/2003-01-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
     
    Diez B. Roggisch, Mar 6, 2005
    #2
    1. Advertising

  3. Piet

    Piet Guest

    > 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
     
    Piet, Mar 9, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim
    Replies:
    2
    Views:
    451
    Richard Tobin
    Jan 29, 2004
  2. kj
    Replies:
    3
    Views:
    22,598
    sandhya
    Mar 27, 2010
  3. Stefan Franke

    XPath and namespaces...

    Stefan Franke, Jan 2, 2005, in forum: XML
    Replies:
    6
    Views:
    1,080
    Martin Honnen
    Jan 3, 2005
  4. bugbear
    Replies:
    5
    Views:
    584
  5. Replies:
    1
    Views:
    466
    Romin
    Apr 20, 2005
Loading...

Share This Page