Skip to content

Commit

Permalink
Add xml_string helper for converting std::string to xmlChar*.
Browse files Browse the repository at this point in the history
  • Loading branch information
vslavik committed Jul 4, 2013
1 parent 3ce3a6c commit ea82953
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/libxml/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class xmlchar_helper
xmlChar *ptr_;
};

inline const xmlChar* xml_string(const std::string& s)
{
return reinterpret_cast<const xmlChar*>(s.c_str());
}

// Formats given message with arguments into a std::string
void printf2string(std::string& s, const char *message, va_list ap);

Expand Down
9 changes: 5 additions & 4 deletions src/libxml/xpath.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "xmlwrapp/node.h"

#include "node_iterator.h"
#include "utility.h"

// libxml includes
#include <libxml/tree.h>
Expand All @@ -45,6 +46,8 @@

#include <map>

using namespace xml::impl;

namespace xml
{

Expand Down Expand Up @@ -104,8 +107,8 @@ struct xpath_context_impl
// TODO: use auto ptr for this
xmlXPathObjectPtr nsptr =
xmlXPathNodeEval(reinterpret_cast<xmlNodePtr>(n.get_node_data()),
reinterpret_cast<const xmlChar*>(expr.c_str()),
ctxt_);
xml_string(expr),

if ( !nsptr )
return NodesView();
Expand Down Expand Up @@ -144,9 +147,7 @@ xpath_context::~xpath_context()

void xpath_context::register_namespace(const std::string& prefix, const std::string& href)
{
xmlXPathRegisterNs(pimpl_->ctxt_,
reinterpret_cast<const xmlChar*>(prefix.c_str()),
reinterpret_cast<const xmlChar*>(href.c_str()));
xmlXPathRegisterNs(pimpl_->ctxt_, xml_string(prefix), xml_string(href));
}

const_nodes_view xpath_context::evaluate(const std::string& expr)
Expand Down

0 comments on commit ea82953

Please sign in to comment.