473,729 Members | 2,155 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!

Nov 18 '05 #1
2 1283

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

Nov 23 '05 #3

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

Similar topics

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
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 image with usemap attribute that equals '#+name attribute of parent map of the above area' equals...
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
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>
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 element. Thankyou in advanced for taking the time to read this and possibly helping me
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>
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
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...
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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...
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();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.