473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath expression help

I'd like to write an XPath expression that gets all nodes with a given
local-name, say 'Customer', within a given namespace. From a prior response
I got the following to get nodes with a specific local-name:

//*[local-name() = 'thenamehere']

But how would I modify this to look only within a given namespace (although
not likely, I could have 'Customer' defined in multiple namespaces)?

Any help would be great!

Paul
Nov 18 '05 #1
2 1279


Paul wrote:
I'd like to write an XPath expression that gets all nodes with a given
local-name, say 'Customer', within a given namespace.


Well XPath has namespace support, in the XPath expression you use a
prefix bound to a namespace URI where that binding happens outside of
the XPath expression language. Thus
//pf:Customer
with the prefix pf bound to the proper namespace URI selects all
Customer elements in that namespace.
How you bind that prefix to the namespace URI depends on where/how you
use XPath, within an XSLT stylesheet you would simply declare that e.g.

<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:pf="http://example.com/ns1" version="1.0">

If you use some API to evaluate XPath expressions you need to check the
documentation, for MSXML see this post
<http://groups.google.c om/group/microsoft.publi c.xml/msg/78260972bdb86cc f>

For .NET you need to use an XmlNamespaceMan ager, bind the prefix you
want to use to the namespace URI and pass the namespace manager as the
second argument to SelectNodes/SelectSingleNod e.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 18 '05 #2
Hi Paul,

Have you updated the namespace in the namespace manager?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 23 '05 #3

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

Similar topics

0
1913
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
0
1340
by: Anna | last post by:
Hi all. I hav eproblems constructing one XPath expression. Here is what I want to do: I want to choose all area tags that belong to a certain image map, having src of the image map. I don't want to use map name for this check, but src of the image map. In other words, I want to say something like this: "Choose all area tags for which src of...
3
1738
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't require that you enter the xpath expression. It may have been something that worked from opening a page in IE. That would be OK. It could have been
2
1635
by: gimme_this_gimme_that | last post by:
What xpath expression would return the category-item having uid sps002 ? <category-list> <category> <uid>GRIDS_MAIN_CATEGORY_UID</uid> <uid-type>Categories</uid-type> <category-item-list> <category-item>
2
7737
by: Echo 8 | last post by:
Is there a simple way of compare dates? I am trying to create a list of perishable stock in an inventory that is near or past its expiration date. I've tried telling it to compare a node's value with a DateTime string, but that doesn't work. I've assumed that it is easier to manipulate today's date instead of the date in my ExpireDate...
6
15499
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>
4
9112
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
2
4713
by: arunairs | last post by:
Hi, Is there a way of validating and XPath? In this case , I am accepting an XPath from the user and I need to validate the XPath syntax. Is there a regular expression available that anyone can direct me to, to validate a XPath? thanks, Arun
0
7912
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...
0
8202
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. ...
0
8216
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...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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...
0
5390
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...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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...

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.