Accessing XML files from Fortran
At this moment, XML is a very popular and widespread format for storing
data in a portable and easily accessible way. There are many
libraries available in languages like C, C++ and Java to read and
otherwise manipulate such files and their contents. For Fortran
programmers, sofar, there have been few options: accessing such files
via a C library is one possibility, but this has as a consequence that you
need the right combination of compilers. It also means that you need to
adapt to the way that particular library works - and that can be
awkward.
With the XML parser that is provided here Fortran programmers have
an all-Fortran solution for reading and writing XML files.
The current implementation does not provide the full set of possibilities
that XML offers, but then there are few if any libraries in existence
that do. (See the documentation
for more information on these limitations).
What the library does provide is the possibility to use XML
files in four different ways:
-
Reading the files in much the same way as an ordinary text file - a
stream-oriented method
-
Directly reading the contents into a data structure that reflects the
structure of the XML file
-
Constructing a tree of data from the XML file with essentially
the same structure
-
Processing the contents using "events", in much the same way as the
original Expat library.
The source code is available via
the
xml-fortran project on SourceForge.
Current version: 1.00 - april 2008
Besides the plain library to read XML files, I have
also written a program, called "xmlreader" that takes a data
definition in the form of a simple XML file and turns that
into a complete Fortran 90 module that can read XML files with the
specified structure. The variables you define via the XML file (both
scalar and array variables of basic types or derived types) are
automatically declared and dealt with in the generated code.
Jacques Germishuizen has contributed a
tutorial which will enable you
to get acquainted with the library and the "xmlreader" program.
New features and bug fixes in version 1.00 (april 2008):
-
Support for components and variables of a fixed shape
-
The xmlreader program now generates a reading routine that can
deal with elements that contain both attributes and character data.
-
Bug fixed w.r.t. the use of default values for individual variables.
-
The xmlreader program also creates a writing routine for writing the
data to an XML file with the same structure.
-
Additional program (xsdconvert) to help convert XSD files to files
acceptable by the xmlreader program.
April, 2008 - Arjen Markus