XPath: selecting on namespaces

Discussion in 'XML' started by kj, Apr 12, 2004.

  1. kj

    kj Guest

    Suppose I have some XML document that contains tags of the form

    <... xmlns:foo="http://www.bar.org/foo">

    <... xmlns:foo="baz">

    <... xmlns:frobozz="http://www.bar.org/foo">

    What's the XPath expression to select the namespace nodes with
    prefix "foo"? And what's the XPath expression to select the
    namespace nodes with value "http://www.bar.org/foo"?

    I am using the Perl module XML::XPath. With it, I know how to
    select namespace nodes with value "baz" (using
    $xpath_obj->find('//namespace::baz')), but I get an error if I try
    to select namespace nodes with value "http://www.bar.org/foo" using
    $xpath_obj->find('//namespace::http://www.bar.org/foo'). I can
    see why the latter would be problematic, since at least the slashes
    in the namespace's value would collide with XPath syntax, but I
    don't know how to escape them. (Actually, the parser seems to
    choke on the colon after http before it gets to do so on the
    slashes.)

    With a full implementation of the XML::XPath standard, I suppose
    I could try something like
    $xpath_obj->find('namespace-uri(//namespace::*)="http://www.bar.org/foo"')),
    but when I do this I get the error "namespace-uri: Function not
    supported".

    I have no clue how to use XML::XPath to select namespace nodes with
    prefix "foo".

    Thanks!

    kj

    P.S. Is there a "standard" forum for XPath-related queries like
    this one?
     
    kj, Apr 12, 2004
    #1
    1. Advertisements

  2. //namespace::*[.='http://www.bar.org/foo']



    Cheers,

    Dimitre Novatchev [XML MVP],
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
     
    Dimitre Novatchev [MVP XML], Apr 12, 2004
    #2
    1. Advertisements

  3. kj

    kj Guest


    Thank you!

    kj
     
    kj, Apr 12, 2004
    #3
  4. kj

    sandhya

    Joined:
    Mar 27, 2010
    Messages:
    1
    Likes Received:
    0
    XPATH in perl

    Hi ,

    I have to select namespace value.
    I am using Xpath in perl.

    <ns1:priceable xmlns:xsi="" xsi:type="ns1:TFuture">

    I have to extarct "ns1:TFuture" value from XML.

    I used xpath expression like below:
    $nodeset = $xp->find("$CODEBASE/Priceables/Priceable/Details/ns1:priceableSet/ns1:priceable/namespace::*['xsi']");



    but not getting any value??

    what is xpath expression for that.?

    Thanks,
    Sandhya
     
    sandhya, Mar 27, 2010
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.