If XML is a Rock, Liberal Parsing is a Hard Place

Historically, the Grace library has been really forgiving, if not lax, in parsing XML formats. In an ideal world, every document is well-formed, but sometimes it’s a seller’s market (take RSS feeds) and you have to work with what you get. Although this worked out well in general, we were having a lot of problems with less-than-well-formed documents every time a new module was checked in. Each OpenPanel module comes with an XML file that contains information about the object classes it represents, their relationships to other classes and their impact on the user interface. It’s easy to make a mistake here, but hard to understand what goes wrong if things don’t work out and you get unhelpful errors.


The value::loadxml() and value::fromxml() methods have been updated to allow for error information to flow back. It was a bit of a feat to get some actually useful information in there, including line numbers. The following error conditions can now be detected:

  • Unbalanced tags around text data.
  • Unbalanced tags with nesting.
  • Invalid mixing of text data with XML/HTML tags.

This update actually turned up some errors in the schema used in one of the test cases. And opencore is now much better at catching dyslectic XML files before they cause problems.

Comments are closed.