[libxml++] Namespace support in Node::find



I could not get Node::find to properly find things I were looking for in a
document with two namespaces in use.  The following patch "fixed it".  Am
I missing something, or is this missing in libxml++? (please reply
directly, i am not on the list)

--- libxml++/nodes/node.cc.orig	2003-05-23 07:10:14.806340666 +0200
+++ libxml++/nodes/node.cc	2003-05-23 07:18:04.733961547 +0200
@@ -97,6 +97,19 @@
 NodeSet Node::find(const std::string& xpath) const
 {
   xmlXPathContext* ctxt = xmlXPathNewContext(_impl->doc);
+
+  // make xpath context aware of namespaces (oystein powertech no 2003-05-23)
+  int numns = 0;
+  xmlNsPtr *nsl = xmlGetNsList(_impl->doc, _impl);
+  if (nsl) {
+    while (nsl[numns]) {
+      numns++; // count number of nses
+    };
+  };
+
+  ctxt->namespaces = nsl;
+  ctxt->nsNr = numns;
+
   ctxt->node = _impl;
   xmlXPathObject* result = xmlXPathEval((xmlChar*)xpath.c_str(), ctxt);
 
@@ -118,6 +131,7 @@
   }
   xmlXPathFreeObject(result);
   xmlXPathFreeContext(ctxt);
+  if (nsl) free(nsl);
 
   return nodes;
 }



-- 
Oystein Homelien, CVO             |  oystein powertech no
PowerTech Information Systems AS  |  http://www.powertech.no/
Nedre Slottsgate 5, N-0157 OSLO   |  tel: +47-23-010-010, fax: +47-2220-0333





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