NOTE: In Eggplant for Mac beginning with version 4.1, SenseTalk includes built-in support for working with XML data (see Chapter 16 � Working with Trees and XML of the SenseTalk Reference manual for full details). The example script presented here is still of interest as an example of parsing text formats or for use with Eggplant for Linux or Windows
The XMLParser suite attached below contains two scripts. The XMLParser script includes two handlers that can be called as functions:
- parseXMLString() takes an XML string and returns a SenseTalk property list containing data extracted from it
- generateXML() does the reverse, taking a property list and returning the data in an XML format
The second script, TestXMLParsing, shows how you might use these functions to work with XML data.
These scripts are intended as an example – a starting point for your own XML processing, rather than a finished product. They work well for the simple case shown here, but are not a complete solution for all possible XML formats, which can vary widely.
One particular known limitation: the current scripts do not handle XML “entities” (such as < to represent a “<” character). For now, extending the script to deal with entities is left as an exercise for the reader.