[libxml++] Problem with setting the default namespace in create_root_node



I sent this message yesterday morning and it hasn't gotten through
yet... I guess whoever handles moderating this list doesn't want to
wade through all the spam to find the occasional on-topic post every
day :-). Since I'm an impatient person, I decided to subscribe and
resend this.



#include <libxml++/libxml++.h>

int main()
{
  xmlpp::Document output_document;
  xmlpp::Element* output_root =
output_document.create_root_node("foo", "urn:xmlns:ExampleCode");
  return 0;
}

As far as I can see from reading the documentation, the above code
should simply create an XML document that, in serialised form, is <foo
xmlns="urn:xmlns:ExampleCode" />. Instead, it throws an exception:

terminate called after throwing an instance of 'xmlpp::exception'
  what():  The namespace () has not been declared.
Aborted

The same happens if I give "" as the third argument. If I give a
non-empty string as the namespace, create_root_node does what it
should do.

I'm not sure if I've investigated this right, but it seems to me that
what's happening is that xmlSearchNs does *not* look for the default
namespace if you pass it a pointer to a null as the third argument - it
wants a null straight instead. A fix that appears to work at least for me is
changing the xmlSearchNs line (libxml++/nodes/node.cc:195) to this:

  xmlNs* ns = xmlSearchNs( cobj()->doc, cobj(), ns_prefix == "" ? NULL
: (xmlChar*) ns_prefix.c_str());




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