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.
| 📄 Parse Strings and files, read in chunks (over 2 GiB too); UTF-8, UTF-16, UTF-32, Latin-1; tolerant, the first problem with its line |
🔎 Query By name, path or parent; path expressions ( select); regular expressions on names, contents, attributes |
🔢 Typed values Contents and attributes read and written as integers, reals, logicals, lists, with an error status |
✏️ Edit and save Change contents, attributes and names by tag ID; insert and delete tags; the prolog kept |
|---|---|---|---|
🖋️ Write any sizexml_writer, element by element, to a file, a unit or memory; only well-formed XML |
🗂️ Huge filesxml_index: the tags without their content, contents read on demand |
📡 Streaming parserxml_handler: your callbacks in source order, nothing stored |
🆓 Free and portable Pure Fortran 2008, no C; gfortran, ifx, nvfortran; fpm, FoBiS, CMake; GPLv3, BSD, MIT |
The tutorial, the cookbook and the reference are on the FoXy website.
Read the settings of a case file as numbers:
use foxy
type(xml_file) :: doc
real(R8P) :: dt
integer(I4P) :: steps
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)Learn the rest in the tutorial, or find a task in the cookbook.
fpm: add FoXy to your fpm.toml.
[dependencies]
FoXy = { git = "https://github.com/Fortran-FOSS-Programmers/FoXy" }FoBiS: clone, fetch the dependencies, build the library (lib/libfoxy.a, modules in lib/mod) or the tests.
git clone https://github.com/Fortran-FOSS-Programmers/FoXy && cd FoXy
fobis fetch
fobis build --mode foxy-static-gnu
fobis build --mode tests-gnu && bash scripts/run_tests.shThen link your program to it:
gfortran -I lib/mod my_program.f90 lib/libfoxy.a -o my_programCMake: fetch the dependencies first (fobis fetch), then cmake -S . -B build && cmake --build build.
See Installation for compilers and options.
- Stefano Zaghi — @szaghi
- Fortran FOSS Programmers — https://github.com/Fortran-FOSS-Programmers
Contributions are welcome — see the Contributing page.
This project is distributed under a multi-licensing system:
- FOSS projects: GPL v3
- Closed source / commercial: BSD 2-Clause, BSD 3-Clause, or MIT
Anyone interested in using, developing, or contributing to FoXy is welcome — pick the license that best fits your needs.