Table of Contents
In the previous sections, XML was used as a formalism for data organization and markup. It was processed either with XML tools or using the Java programming language, which provides a fairly complete set of tools for processing XML documents. Since this tree based approach to data organization is now well accepted, tools for XML file parsing and creation have been developed for other programming languages. XML packages exist for C++, C#, Perl and even Fortran with capabilities and programming interfaces similar to the ones we have presented for Java. XML thus serves as convenient exchange language between programs written in different programming languages.
Of particular interest is libxml2
library [73]
which is an XML parser and toolkit written in C with a variety of language bindings for
other programming languages. It is very portable and can be run on most systems. It is most
often accessible from the command line thru the xmllint
command.
The parser can validate with DTD, XML Schema, Relax NG or Schematron. XPath and XSLT are
also implemented but at the 1.0 level. Some features of XSLT 2.0 have been implemented
in a separate project [74].
We will first present how XML data can be processed in Ruby[44], a dynamically typed scripting language known for its flexibility and its large library of tools for creating Web-based applications. We then show how XML can be processed with Python [32], a popular script language, PHP [76], a server-side script language for the Internet, JavaScript [68] used in web browsers, and Swift [85], , a statically typed script language. For mainly historical purposes, we also describe EcmaScript for XML (E4X).[66],
We will illustrate the use of XML within these programming languages using the same compact and expand applications that we have used in previous chapters. This will allow an easier comparison between different programming languages.
Even though we have argued until now that XML is the ideal markup language, we will describe in this chapter some alternative approaches for a tree based data organization. It should be remembered that most of these simplified XML packages do not provide validation for their input, which must be performed by other means. In the last section of this chapter, we will show other XML competitors for exchanging data between programs: JavaScript Object Notation (JSON) [71] and YAML (YAML Ain't a Markup Language) [90]. These notations are geared toward the production of a human-readable notation for describing tree based informations compared with XML. This goal is achieved but they do not provide any notion of validation or transformation tools within the exchange language itself. But in the context of simple information transfers betweens programs (e.g. between a browser and a Web server using the AJAX technology for a more pleasant interaction) not needing sophisticated validation or transformation, they provide interesting lightweight alternatives.