[libxml++] Node::find(): Use libxml functions instead of direct C access.



commit bc19fa7c26e5f42efc26c22757588169e0849fe8
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Jun 13 22:32:24 2010 +0200

    Node::find(): Use libxml functions instead of direct C access.
    
    * libxml++/nodes/node.cc: Use xmlXPathNodeSetIsEmpty(),
    xmlXPathNodeSetGetLength() and xmlXPathNodeSetItem() instead of direct
    xmlNodeSet struct access.

 ChangeLog              |    8 ++++++++
 libxml++/nodes/node.cc |   13 +++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 475917a..fd3c753 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-13  Murray Cumming  <murrayc murrayc com>>
+
+	Node::find(): Use libxml functions instead of direct C access.
+
+	* libxml++/nodes/node.cc: Use xmlXPathNodeSetIsEmpty(), 
+	xmlXPathNodeSetGetLength() and xmlXPathNodeSetItem() instead of direct 
+	xmlNodeSet struct access.
+
 2010-06-13  Murray Cumming  <murrayc murrayc com>
 
 	Manual: Use git.gnome.org as the link to the examples source code.
diff --git a/libxml++/nodes/node.cc b/libxml++/nodes/node.cc
index b18752b..4b53b30 100644
--- a/libxml++/nodes/node.cc
+++ b/libxml++/nodes/node.cc
@@ -276,11 +276,16 @@ static NodeSet find_impl(xmlXPathContext* ctxt, const Glib::ustring& xpath)
 
   xmlNodeSet* nodeset = result->nodesetval;
   NodeSet nodes;
-  if( nodeset )
+  if( nodeset && !xmlXPathNodeSetIsEmpty(nodeset))
   {
-    nodes.reserve( nodeset->nodeNr );
-    for (int i = 0; i != nodeset->nodeNr; ++i)
-      nodes.push_back(static_cast<Node*>(nodeset->nodeTab[i]->_private));
+    const int count = xmlXPathNodeSetGetLength(nodeset);
+    nodes.reserve(count);
+    for (int i = 0; i != count; ++i)
+    {
+      xmlNodePtr cnode = xmlXPathNodeSetItem(nodeset, i);
+      Node* cppNode = static_cast<Node*>(cnode->_private); //libxml creates a C++ instance for us here.
+      nodes.push_back(cppNode);
+    }
   }
   else
   {



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