So, I was chatting with Murray on IRC and wanting namespace awareness in
libxml++. He challenged me to do some hacking on it myself, so I had a
go this afternoon. Daniel Veillard indicated that libxml2 is never
likely to get SAX2, and that for namespaces he'd encourage the use of
the XmlTextReader interface.
Please be aware that my C++ skills are definitely in the "apprentice"
category, and I probably indented incorrectly to someone's great
irritation.
That said, here's a preliminary wrapper and example program for the
XmlTextReader stuff from libxml2. It's a diff against today's CVS HEAD
plus these new files I added:
examples/reader/Makefile.am
examples/reader/main.cc
examples/reader/example.xml
libxml++/parsers/reader.cc
libxml++/parsers/reader.h
It's only partially complete, in particular only the constructor where
you pass a filename is done.
The biggest trouble so far is that the underlying XmlTextReader stuff
handles allocation and freeing of things differently than the normal
parsers. This means that the construct() and destruct() functions just
don't work. I disabled them entirely for the purposes of this wrapper,
but it needs figuring out properly -- a bit beyond the scope of one
evening's hacking for me, unfamiliar as I am with the magic of libxmlpp
internals. However, this disabling meant I couldn't implement the two
methods which allow sniffing of the current Node and Document.
The other thing to note is that every time you get an xmlChar* back from
a method, it's your responsibility to free it with xmlFree().
I hope that this is a good enough start for someone with more clues than
I to improve. Alternatively, I'd be happy to receive a few pointers
from folk on how best to make the wrapper more C++ idiomatic, and in
particular solve the construct/destruct issues.
The *good news* is that this stuff works for parsing namespace-enabled
XML documents.
cheers
-- Edd
|