473,756 Members | 3,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath: selecting on namespaces

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('namespac e-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.
Jul 20 '05 #1
2 2972

"kj" <so***@987jk.co m> wrote in message
news:c5******** **@reader1.pani x.com...


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('namespac e-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.

Jul 20 '05 #2
kj
In <c5***********@ ID-152440.news.uni-berlin.de> "Dimitre Novatchev [MVP XML]" <dn********@yah oo.com> writes:
"kj" <so***@987jk.co m> wrote in message
news:c5******* ***@reader1.pan ix.com...

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.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2399
by: Colin Green | last post by:
I have come across what seems like a failing in the .Net XML classes. Many people have posted requesting how to write an XPath query with namespace prefixes that works. The solution shown in all the posts I have seen is of the form: --------------------------------------------- XmlDocument doc = new XmlDocument(); doc.Load(@"c:\foobar.xml"); XmlNamepaceManager nmMgr = newNamespaceManager(doc); nmMgr.AddNamespace("abc", "www.my.uri");
12
3491
by: Lawrence Oluyede | last post by:
I've some problems with filtering out a specific element by the following xml snippet (is part of a bigger xml document): <entry> <link href="http://www.blogger.com/atom/5281182/108809850419059234" rel="service.edit" title="test" type="application/x.atom+xml"/> <author> <name>Lawrence</name> </author> <issued>2004-06-24T19:34:04+02:00</issued>
1
5808
by: Robert | last post by:
I am having a problem selecting nodes using the XMLnodelist Selectnodes using XPATH when I use XML SPY is successfully queries but when is use VB.net it comes up with nothing. Here is my code Dim nodess As XmlNode nodess = myNode.SelectSingleNode("//Web") If nodess Is Nothing Then SQLrw.Delete()
6
15510
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
3
6808
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
14
2006
by: Mat| | last post by:
Hello :-) I am learning XPath, and I am trying to get child nodes of a node whose names do *not* match a given string, e.g : <dummy> <example> <title>Example 1</title> <body>this is an example</body>
6
7299
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot figure out what is going on here. I have taken it all the way back to just selecting the configuration node (top level node), and it fails! How can this line fail (returns null)??
14
17164
by: Mikhail Teterin | last post by:
Hello! What's would be the syntax for a query, which would allow me to get only the elements with non-empty text-nodes? For example, from: <a><b></b></a> <c/> <d><e>meow</e></d>
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.