[libxml++] Node::find(): Check xmlNode::type for a XML_NAMESPACE_DECL.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml++] Node::find(): Check xmlNode::type for a XML_NAMESPACE_DECL.
- Date: Sun, 13 Jun 2010 21:50:47 +0000 (UTC)
commit b224adbd2cc634303390a8e1bbef676c2075ab1f
Author: Murray Cumming <murrayc murrayc com>
Date: Sun Jun 13 23:50:40 2010 +0200
Node::find(): Check xmlNode::type for a XML_NAMESPACE_DECL.
* libxml++/nodes/node.cc: find_impl(): if the xmlNode has type
XML_NAMESPACE_DECL then it is actually a xmlNs, which is not like a xmlNode
at all (thanks to the awful undocumented libxml++ system of struct
inheritance).
So we just igore these items. We need to decide what the caller really
expects.
ChangeLog | 11 +++++++++++
libxml++/nodes/node.cc | 21 +++++++++++----------
2 files changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b07a8d0..bd6d0cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2010-06-13 Murray Cumming <murrayc murrayc com>
+ Node::find(): Check xmlNode::type for a XML_NAMESPACE_DECL.
+
+ * libxml++/nodes/node.cc: find_impl(): if the xmlNode has type
+ XML_NAMESPACE_DECL then it is actually a xmlNs, which is not like a xmlNode
+ at all (thanks to the awful undocumented libxml++ system of struct
+ inheritance).
+ So we just igore these items. We need to decide what the caller really
+ expects.
+
+2010-06-13 Murray Cumming <murrayc murrayc com>
+
Node::find(): Revert some of my previous change because it breaks some code.
* libxml++/nodes/node.cc: find_impl(): Restore the previous behaviour,
diff --git a/libxml++/nodes/node.cc b/libxml++/nodes/node.cc
index bdbc2c2..e4bb723 100644
--- a/libxml++/nodes/node.cc
+++ b/libxml++/nodes/node.cc
@@ -283,16 +283,17 @@ static NodeSet find_impl(xmlXPathContext* ctxt, const Glib::ustring& xpath)
for (int i = 0; i != count; ++i)
{
xmlNode* cnode = xmlXPathNodeSetItem(nodeset, i);
-
- // Usually, this cnode is one that was provided to on_libxml_construct(),
- // so we have already created a C++ Node and set it in _private.
- // TODO: But sometimes the xmlNode::_private contains a
- // pointer to the actual xmlNode (which has the Node* in _private),
- // Maybe libxml abuses xmlNode::_private, but only sometimes.
- // I only discovered this through experimentation. murrayc.
- // See bug https://bugzilla.gnome.org/show_bug.cgi?id=386013
- xmlNode* cnodeReal = cnode; //static_cast<xmlNode*>(cnode->_private);
- Node* cppNode = static_cast<Node*>(cnodeReal->_private);
+ if(cnode->type == XML_NAMESPACE_DECL)
+ {
+ //In this case we would cast it to a xmlNs*,
+ //but this C++ method only returns Nodes.
+ std::cerr << "Node::find_impl: ignoring an xmlNs object." << std::endl;
+ continue;
+ }
+
+ //TODO: Check for other cnode->type values?
+
+ Node* cppNode = static_cast<Node*>(cnode->_private);
nodes.push_back(cppNode);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]