Re: [libxml++] default namespace



panoply att net wrote:
> The reading I've done tells me that with XML1.1 there is no way to use >default namespaces in XPath searches. Ok, so now I'd like to know the >work-around. One thing I found in another post was this:

That is true.

> If I understand the above code correctly, it is assigning a prefix to >the default namespace, then using that prefix in XPath searches. Is >that correct? I AM PERFECTLY HAPPY resolving my problem this way (if >it will work). But I want to find out if this can be done through the >libxml++ wrapper - and if this over-all approach is Kosher.

Yes it is the only way. I included changes to my local version of libxml++ in node.cc. In node class I added namespaceprefix and namespaceref items. Then in node::find method I added this before the search is to be executed:

if (!nsprefix_.empty() && !nsref_.empty()) {
 xmlXPathRegisterNs( ctxt,
 reinterpret_cast<const xmlChar*>(nsprefix_.c_str()),
 reinterpret_cast<const xmlChar*>(nsref_.c_str()));
  };
}

Allso it was needed to add special new method for setting these two values in node class that look like this:

void Node::set_namespace_with_ref(const std::string& ns_prefix, const std::string& ns_ref) { xmlNs* ns = xmlSearchNs( cobj()->doc, cobj(), (xmlChar*)ns_prefix.c_str() );
  if(!ns) {
      nsprefix_ = ns_prefix;
      nsref_ = ns_ref;
  } else {
      nsprefix_.clear();
      nsref_.clear();
  }
}

With this everything works just fine.

Darko





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