Re: [xml] Xpath namespaces

On Tue, Aug 21, 2007 at 04:16:33PM -0400, Glenn MacGregor wrote:
   I  an  using xmlXPathRegisterNS to register the soap namespace, but in
   the  getUIDResponse  the default namespace is changed. I assume I have
   to   register  that  ([6]  as  the
   default at some point.

   Is this possible, how would I do this action?

  Not as the default, normally, and use the prefix in teh XPath query.
  This is XML namespace FAQ #1, covered here dozens of times and zillions
on any XML fora. The answer is the following:

   - 'foo' in XPath *cannot* match a namespaced element or attribute name
     whatever the default namespace or context information for the XPath
   - you must use a prefix, bound to the namespace name used for the default
     namespace in the query
     'prefix:foo' and define 'prefix' accordingly

This behaviour is actually a good thing even if newbies tends to not
understand it, following example provided to help understand the real

   <sub xmlns="ns1">
   <sub xmlns="ns2">

it is *good* that "//foo" returns only one node on that document!
for the same reason that "//ns1:foo" with a namespace context {ns1:"ns1"}
also returns only one node.


Red Hat Virtualization group
Daniel Veillard      | virtualization library
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]