Developer's Diary
Software development, with Terry Ebdon
|
SimpleMind is excellent, and inexpensive, mind mapping software. I've used it for many years, and like it a lot. But... I hit a couple of problem with it recently. Not with the software itself, but the way I was using it.
SimpleMind files have a .smmx file type. The file is a zip archive containing an XML file and the embedded document images. I've created a test file with five map nodes, two external links and an embedded image. This was copied from a “corrupt” branch, so will have a problem.
The test Mind Map looks like this:
Cracking open the zip file reveals this:
├───document │ mindmap.xml │ └───images db7f9c0c717f68833d76f51e4eeef85df359bba8.png hWPR03nipkq5KJPfDTtXIQ.png
The smmx file contains two embedded images, which is one more than you might expect.
A peek at the XML shows it's easy enough to understand. It would be nice if it was indented though. That's a job for the W3C's HTML tidy tool:
That, slightly obscure, command will:
This will show a heap of invalid character warnings. That's fine; the output file is throw-away. I'm just using it to “pretty-print” the file.
The tidied XML is now nicely indented, making it a lot easier to the see the XML's structure.
From the tidied file you can see this top level structure:
I've omitted some irrelevant tags from the above diagram, for clarity.
The example code, SmmxTest.groovy, is available on BitBucket under an Apache 2.0 licence. Line numbers, in the following description, match those in the file on BitBucket.
First I crack open the ZIP file, at line 12, using Java's ZipFile class:
Then iterate through the entries, until the mindmap XML file is found:
Now load the XML into groovy's XmlParser:
There's a little hack at line 21, notice it's not sending the entire XML string to the XmlParser. That odd looking xml.text[41..-1]
strips off the first 40 characters. Why? Because that's the XML header and end-of-line line characters.
At line 24 I check that the name of the top-level element matches the one I expect, based on the output from HTML Tidy. Note the use of an assertion; another indication that this is test software. Production software should anticipate an incorrect file being provided, and behave gracefully.
At line 29 I display the mind map's title. Then, at lines 30 to 36, the child images are examined.
Note the Groovy syntax used, which is very similar to XPath.
Find me coding on GitHub, networking on LinkedIn, answering questions on Stack Exchange and hanging out on twitter.