Re: [xml] XPATH question when used with namespace

On Tue, Apr 08, 2003 at 04:30:43PM -0600, Chris Coy wrote:

When accessing any given element name within a tree document, the
element name stored within xmlNodePtr->name is the element name without
the namespace, as one would expect.

  "as one would expect" is as YOU expect. And taht's not the case
for a zillion of very good reasons. namespaces are separate objects
linked from the ns field when present.

But with XPATH, when trying to access a particular element nodeset that
is part of a namespace, the only solution I came upon was to use the
contains clause. Is this normal behavior for XPATH or a Gnome feature?

  It's perfectly normal for XPath, XPath was *NOT* designed to be
used in isolation, as a result there is no way to provide namespace
bindings within the XPath syntax. There are APIs to provide this
bindings in libxml2 XPath module.

Given the following document hierarchy here is my query:

  Not the normal way, time to read the XPath spec:
local-name() and namespace-uri() were designed for this. 
Using contains() is simply baroque, and doing the node match based on the
namespace prefix instead of the namespace name (the URI) is really bad 
XML coding practice (i.e. your code will break as soon as someone change
the prefix mapping to the namespace).

The above query was the only solution I discovered to access the
"ds:Row" nodeset 
Any clarification appreciated.

  I think you need to read books about XPath and XML in general,
and the specs of course. Correct solution to those problems are
standard, and not even dependant on libxml2 specific implementation.


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]