A Better XML Parser through Functional Programming
This paper demonstrates how a higher-level, declarative view of XML parsing as folding over XML documents has helped to design and implement a better XML parser. By better we mean a full-featured, algorithmically optimal, pure-functional parser, which can act as a stream processor. By better we mean an efficient SAX parser that is easy to use, a parser that does not burden an application with the maintenance of a global state across several callbacks, a parser that eliminates classes of possible application errors.
This paper describes such better XML parser, SSAX. We demonstrate that SSAX is a better parser by comparing it with several XML parsers written in various (functional) languages, as well as with the reference XML parser Expat. In the experience of the author the declarative approach has greatly helped in the development of SSAX. We argue that the more expressive, reliable and easier to use application interface is the outcome of implementing the parsing engine as an enhanced tree fold combinator, which fully captures the control pattern of the depth- first tree traversal.
KeywordsXML parsing traversal tree fold Scheme Haskell
Unable to display preview. Download preview PDF.
- 1.Anderson, J.: Common Lisp support for the ‘Extensible Markup Language’ (CL-XML). Version 0.906, June 2, 2001. http://homepage.mac.com/james_anderson/XML/documentation/cl-xml.html
- 2.Cooper, C.: Using Expat. xml.com, September 1, 1999. http://www.xml.com/pub/a/1999/09/expat/index.html
- 3.Dunford, M.: DOM XML: An Alternative to Expat. http://www.phpbuilder.com/columns/matt20001228.php3
- 6.Gibbons, J., Jones, G.: The Under-appreciated Unfold. Proc. Intl. Conf. Functional Programming, pp. 273–279, Baltimore, Maryland, September 27-29, 1998.Google Scholar
- 7.Kiselyov, O.: Functional XML parsing framework: SAX/DOM and SXML parsers with support for XML Namespaces and validation. Version 4.9, September 5, 2001. http://pobox.com/~oleg/ftp/Scheme/xml.html#XML-parser
- 8.Lindig, C.: Tony-a XML Parser and Pretty Printer. Version 0.8. http://www.gaertner.de/~lindig/software/tony.html
- 9.van Mourik, H.: XML parser in Scheme. Version: 0.9.23, June 2, 1998. http://student.twi.tudelft.nl/~tw585306/
- 10.Neumann, A.: The Functional XML Parser. Version 1.4.4, October 30, 2000. http://WWW.Informatik.Uni-Trier.DE/~aberlea/Fxp/
- 11.Sheard T., Fegaras, L.: A fold for all seasons. Proc. Conf. on Functional Programming and Computer Architecture (FPCA’93), pp. 233–242, Copenhagen, Denmark, June 1993.Google Scholar
- 12.Wallace M., Runciman, C.: HaXml. Version 1.02 release, May 3, 2001. http://www.cs.york.ac.uk/fp/HaXml/
- 13.World Wide Web Consortium. Extensible Markup Language (XML) 1.0 (Second Edition). W3C Recommendation October 6, 2000. http://www.w3.org/TR/REC-xml
- 14.World Wide Web Consortium. XML Information Set. W3C Candidate Recommendation. May 14, 2001. http://www.w3.org/TR/xml-infoset