Fortran XML parser for poor people — a KISS pure Fortran 2008+ OOP library for parsing and emitting XML files and tags.
- Parse XML from a string or a file into a linearised DOM with full hierarchy tracking
- Nested tags and repeated tags with the same name supported
- Create tags programmatically with attributes, text content, and nesting
- Emit tags to string or write atomically to a file unit
- Self-closing tags, indentation, and partial emission (start / content / end separately)
- Add and delete tags and attributes by name
- OOP designed — two clean types (
xml_tag,xml_file), all functionality as type-bound procedures - No C bindings, no wrappers — pure Fortran 2008+ with
implicit nonethroughout - Multi build system: fpm, FoBiS.py, CMake
- 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.
Parse an XML string and query a tag's content:
use foxy, only: xml_file
implicit none
type(xml_file) :: xfile
character(len=:), allocatable :: val
call xfile%parse(string= &
'<config>'//new_line('A')// &
' <dt unit="s">0.01</dt>'//new_line('A')// &
' <nstep>1000</nstep>'//new_line('A')// &
'</config>')
val = xfile%content('dt')
print *, val ! 0.01Create and emit a tag programmatically:
use foxy, only: xml_tag
implicit none
type(xml_tag) :: tag
tag = xml_tag(name='point', &
attributes=reshape([['x','1'],['y','2'],['z','3']], [2,3]))
print *, tag%stringify() ! <point x="1" y="2" z="3"/>Add FoXy as a dependency in your fpm.toml:
[dependencies]
FoXy = { git = "https://github.com/Fortran-FOSS-Programmers/FoXy" }git clone --recursive https://github.com/Fortran-FOSS-Programmers/FoXy.git
cd FoXy
FoBiS.py build -mode tests-gnu && bash scripts/run_tests.shgit clone --recursive https://github.com/Fortran-FOSS-Programmers/FoXy.git
cd FoXy
mkdir build && cd build
cmake ..
make && make install| Tool | Command |
|---|---|
| fpm | fpm build && fpm test |
| FoBiS.py | FoBiS.py build -mode tests-gnu |
| CMake | cmake .. && make |