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?


    --
    NOTE: In my address everything before the period is backwards.
    kj, Apr 12, 2004
    #1
    1. Advertising

  2. "kj" <> wrote in message
    news:c5dkrg$mak$...
    >
    >
    > 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"?


    //namespace::*[name()='foo']


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


    //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

    >
    > 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?
    >
    >
    > --
    > NOTE: In my address everything before the period is backwards.
    Dimitre Novatchev [MVP XML], Apr 12, 2004
    #2
    1. Advertising

  3. kj

    kj Guest

    In <c5dm8b$fe3f$-berlin.de> "Dimitre Novatchev [MVP XML]" <> writes:

    >"kj" <> wrote in message
    >news:c5dkrg$mak$...
    >>
    >> 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"?


    >//namespace::*[name()='foo']


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


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



    Thank you!

    kj

    --
    NOTE: In my address everything before the period is backwards.
    kj, Apr 12, 2004
    #3
  4. kj

    sandhya

    Joined:
    Mar 27, 2010
    Messages:
    1
    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. 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. Alastair Cameron
    Replies:
    1
    Views:
    7,399
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  2. Jim
    Replies:
    2
    Views:
    449
    Richard Tobin
    Jan 29, 2004
  3. Stefan Franke

    XPath and namespaces...

    Stefan Franke, Jan 2, 2005, in forum: XML
    Replies:
    6
    Views:
    1,076
    Martin Honnen
    Jan 3, 2005
  4. Replies:
    1
    Views:
    465
    Romin
    Apr 20, 2005
  5. Omar
    Replies:
    4
    Views:
    18,073
    Patrick TJ McPhee
    Jun 21, 2005
Loading...

Share This Page