XPath: selecting on namespaces

K

kj

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?
 
D

Dimitre Novatchev [MVP XML]

kj said:
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
 
K

kj

In said:
kj said:
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"?


Thank you!

kj
 
Joined
Mar 27, 2010
Messages
1
Reaction score
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
 

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

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top