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]http://www.hidden.com/Servicecs/1.0)  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
     query.
   - 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
problem:

 <doc>
   <sub xmlns="ns1">
     <foo/>
   </sub>
   <sub>
     <foo/>
   </sub>
   <sub xmlns="ns2">
     <foo/>
   </sub>
 </doc>

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.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
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]