Skip to content

FoXyFortran XML for poor people

Read, query, edit and write XML from modern Fortran: a DOM for documents, an index for huge files, a streaming parser with your own callbacks, a writer for any size. Pure Fortran 2008, one module: use foxy.

the FoXy logo, a low-poly arctic fox whose eyes and white blaze read </>

In a nutshell ​

Read the settings of a case file, case.xml (the input of the tutorial), as numbers:

f90
program read_number
use foxy
implicit none
type(xml_file) :: doc
real(R8P)      :: dt
integer(I4P)   :: steps
logical        :: adaptive

call doc%parse(filename='case.xml')
call doc%get_content(id=doc%find(path='case/time/dt'), value=dt)
call doc%get_content(id=doc%find(path='case/time/steps'), value=steps)
call doc%get_content(id=doc%find(path='case/time/adaptive'), value=adaptive)
print '(ES10.3,1X,I0,1X,L1)', dt, steps, adaptive
endprogram read_number
$ read_number
 1.000E-03 500 T

Start with the tutorial, or look up a task in the cookbook.

See it run ​

fx, a small command line tool built on FoXy, on the files of the tutorial: the outline of a case file, a value read as a number, a path expression, a regular expression, a malformed file, and a UTF-16 file streamed through a handler.

a terminal session of fx, a tool built on FoXy: the tree of case.xml, case/time/dt read as a real, select of the wall boundaries, contents matching a regular expression, the problem of a malformed file with its line, and the events of a UTF-16 file

The whole tool is one program: tour.f90.