Re: [xml] XPath question
- From: Daniel Veillard <veillard redhat com>
- To: Jesse Pelton <jsp PKC com>
- Cc: xml gnome org, Ed Day <eday obj-sys com>, Igor Zlatkovic <igor zlatkovic com>
- Subject: Re: [xml] XPath question
- Date: Wed, 4 Aug 2004 12:20:23 -0400
On Wed, Aug 04, 2004 at 11:45:29AM -0400, Jesse Pelton wrote:
So how do you solve the original problem? That is, how do you construct
an expression to select elements in a particular default namespace?
You should not care whether it is a default namespace or a normal
namespace. You build the XPath query using whatever prefix you want
map the prefix to the namespace name (i.e. the URI) in the XPath context
and run the query that way.
As soon as you start selecting on the kind of prefix in the target
document there is something wrong, whether it's "foo", "bar" or the
default one should not matter from a semantic viewpoint.
- Assuming foo is mapped to your namespace name "bar" in the XPath context
- assuming n is the name of the elements you're searching
then
//foo:n
is way better than
//*[local-name() = 'n' and namespace-uri() = 'bar']
Now if you still want to only pick elements which are in the default
namespace you can still do
- Assuming foo is mapped to your namespace name in the XPath context
- assuming n is the name of the elements you're searching
then
//foo:n[name() = 'n']
will do it, and will be quite cheaper than //* and then a selection.
the name() function retrieves the qname and name() = 'n' ensure there
is no prefix.
Daniel
--
Daniel Veillard | Red Hat Desktop team http://redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]