← Back to team overview

dolfin team mailing list archive

Re: XML parsing

 

On Fri, Aug 06, 2010 at 09:02:00PM +0100, Garth N. Wells wrote:
> I have trouble following the logic in the DOLFIN XML io code, which I
> suspect is because of the pointers to callback functions being passed to
> libxml2. Has anyone looked at libxml++
> (http://library.gnome.org/devel/libxml++-tutorial/stable/) which
> provides C++ bindings to libxml2?

No, and I'm not sure if it's worth the trouble.

I think the libxml2 interface is not much of a problem, at least not
since we realized how to only set the callbacks we are interested in:

  XMLFile::XMLFile(std::ostream& s)
  : GenericFile(""), sax(0), outstream(&s)
  {
    // Set up the sax handler.
    sax = new xmlSAXHandler();

    // Set up handlers for parser events
    sax->startDocument = sax_start_document;
    sax->endDocument   = sax_end_document;
    sax->startElement  = sax_start_element;
    sax->endElement    = sax_end_element;
    sax->warning       = sax_warning;
    sax->error         = sax_error;
    sax->fatalError    = sax_fatal_error;
  }

Ola did a very good job at redesigning the parsing to allow reuse of
code. For example, we can reuse the parsing of MeshFunction data
inside the <data> tag inside the <mesh> tag. Previously, every top
level tag had its own implementation which prevented reuse of code for
parsing nested data.

This is what makes the implementation difficult to follow, but it's
essentially a stack of parsers where we push and pop the handler
currently responsible for accepting the callbacks from libxml2 when it
reads data.

I don't think it would be easier if we used the C++ interface. It
would probably be less transparent. Right now, our interaction with
libxml2 is very minimal: setting the callbacks and receiving the data
parsed by libxml2.

--
Anders

Attachment: signature.asc
Description: Digital signature


Follow ups

References