472,328 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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 1216


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:stylesheet
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.com/group/microsoft.public.xml/msg/78260972bdb86ccf>

For .NET you need to use an XmlNamespaceManager, bind the prefix you
want to use to the namespace URI and pass the namespace manager as the
second argument to SelectNodes/SelectSingleNode.

--

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
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...
0
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...
3
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...
2
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>...
2
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. ...
6
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>...
4
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
2
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...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

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.