A Better XML Parser through Functional Programming

  • Oleg Kiselyov
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 2257)


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.


XML parsing traversal tree fold Scheme Haskell 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Anderson, J.: Common Lisp support for the ‘Extensible Markup Language’ (CL-XML). Version 0.906, June 2, 2001.
  2. 2.
    Cooper, C.: Using Expat., September 1, 1999.
  3. 3.
    Dunford, M.: DOM XML: An Alternative to Expat.
  4. 5.
    Hutton, G.: A tutorial on the universality and expressiveness of fold. Journal of Functional Programming, 9(4):355–372, July 1999.zbMATHCrossRefMathSciNetGoogle Scholar
  5. 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
  6. 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.
  7. 8.
    Lindig, C.: Tony-a XML Parser and Pretty Printer. Version 0.8.
  8. 9.
    van Mourik, H.: XML parser in Scheme. Version: 0.9.23, June 2, 1998.
  9. 10.
    Neumann, A.: The Functional XML Parser. Version 1.4.4, October 30, 2000. http://WWW.Informatik.Uni-Trier.DE/~aberlea/Fxp/
  10. 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
  11. 12.
    Wallace M., Runciman, C.: HaXml. Version 1.02 release, May 3, 2001.
  12. 13.
    World Wide Web Consortium. Extensible Markup Language (XML) 1.0 (Second Edition). W3C Recommendation October 6, 2000.
  13. 14.
    World Wide Web Consortium. XML Information Set. W3C Candidate Recommendation. May 14, 2001.

Copyright information

© Springer-Verlag Berlin Heidelberg 2002

Authors and Affiliations

  • Oleg Kiselyov
    • 1
  1. 1.Software EngineeringNaval Postgraduate SchoolMonterey

Personalised recommendations