Saturday, March 22, 2008

XML in Maple 11 (bug and fix)

Maple may corrupt its own file format, making it impossible to load a worksheet.

Maple 11's worksheet format is an XML compliant document. XML-based software requires that documents be "well-formed" in order to be considered "valid", and acceptable for processing. One well-formedness constraint is that the character set included in the document is consistent with the character encoding selected for the document, or the default encoding (which is UTF-8).
Maple 11 instructions such as printf can cause invalid characters to be produced as characters in an output block. It appears that Maple 11 will incorrectly save such output blocks without properly encoding the characters or escaping them as CDATA sections. When Maple 11 attempts to re-open the worksheet , parsing of the XML fails at the non-well-formed block and a warning given that the worksheet is incomplete.

The user may believe that a significant portion of work has been lost, but that would only be true if they save the file again. In fact, the worksheet is still complete, but Maple 11 is unable to parse the document to reconstruct its "working memory" of the worksheet.

An effective workaround is to open the worksheet in a text editor (notepad), programmer's editor (vi/emacs, etc), or XML editor (oXygenXML, XMLSpy, etc) and delete the invalid output block, saving the result as a new worksheet (.ws) file. I prefer to use oXygenXML rather than a text editor. OxygenXML helps spot the well-formedness errors quickly, and ensures that only well-formed XML is saved back to disk. After saving, the new worksheet can be fully opened in Maple 11, and the code modified to avoid generating invalid character codes.

A proper fix is for Maple 11 to avoid dumping incorrectly coded characters to the XML. Maple 11 should generate proper UTF-8 encoding sequences, and/or substitute certain subsets of UTF-8 outside of the usual ASCII range with numeric character references.

Although I could fix this easily, others may not be so lucky. Since there was no FAQ dealing with the issue I decided to report it and post it to my blog.

No comments: