Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Warning
titleversion 3.0.0

Please note that this documentation covers version 3.0.0 . There are new features in version 3.2.0  that are not yet covered in this document.


Info
titlesource

Note that this document is based on TeX  file documentation prepared by Thomas. You can find TeX  file inside GIT  repository of xmllib  inside doc  directory

Code Block
> git clone ssh://git@git.iter.org/lib/xmllib.git
> cd xmllib/doc


What is XMLLIB?

XMLLIB is a library for parsing xml-les in Fortran. This means that it provides subroutines for extracting values from an xml file.

...

Code Block
type(ids_parameters_input), intent(in) :: codeparam
call file2buffer('input.xml',                'input.xsd',      'input_default.xml', &
                  codeparam%parameters_value, codeparam%schema, codeparam%parameters_default)

The xml2eg interface

To parse data using the xml2eg  interface one first translate the xml data into an abstract document of type type_xml2eg_document using the subroutine xml2eg_parse_memory.

Once the data is read into the document data fields can be accessed using the subroutine xml2eg_get. This subroutine is polymorphic and can read strings, scalar and arrays of integers, single and double precision floats and booleans. To read a particular value from the xml-tree, use an xpath  format (e.g. tree/branch/leaf ). Note however, that the xml2eg  format assumes that the root level is called parameters and this root level is implicit in the xpath. Thus, while the absolute xpath would be /parameters/tree/branch/leaf the value of the leaf is access by requesting tree/branch/leaf.

The interface to xml2eg_get is:
\begin{verbatim}
subroutine xml2eg_get(xml2eg_document, path, out, errorflag)
type(type_xml2eg_document) :: xml2eg_document
character(len=*), intent(in) :: path
<OutType>, intent(out) :: out
logical, optional :: errorflag
\end{verbatim}
Here \texttt{<OutType>} is either \texttt{integer}, \texttt{integer, dimension(:)}, \texttt{real(r4)}, \texttt{real(r4) dimension(:)}, \texttt{real(r8)}, \texttt{real(r8), dimension(:)}, , \texttt{boolean}, \texttt{boolean, dimension(:)}, , \texttt{character(:)}, where \texttt{r4} and \texttt{r8} are defined in the module \texttt{xmllib\_types}.
The most simple usage of xml2eg is then:
\begin{verbatim}
use xml2eg_mdl, only: xml2eg_parse_memory, xml2eg_get, &
type_xml2eg_document
type(type_xml2eg_document) :: doc
character(len=132), dimension(:), pointer ::parameters
integer :: val
call xml2eg_parse_memory( parameters , doc )
call xml2eg_get(doc , 'tree/branch/leaf' , val)
\end{verbatim}

The xml2eg interface also includes error handling. When calling \texttt{xml2eg\_get} one may provide a fourth (optional) argument, which is a output argument that returns a boolean error flag (true is the reading failed and false it is was successful).
\begin{verbatim}
logical :: execution_error
...
call xml2eg_get(doc , 'tree/branch/leaf' , val, execution_error)
if (execution_error) then
...
end if
\end{verbatim}

Once finished reading the xml-document all allocated data has to be freed. This is achieved by calling \texttt{xml2eg\_free\_doc}.
\begin{verbatim}
call xml2eg_free_doc(doc)
\end{verbatim}