The Open FUSION Toolkit 26.6
An open-source framework for fusion and plasma science and engineering
Loading...
Searching...
No Matches
oft_xml Module Reference

Detailed Description

Libxml2 DOM interface for OFT.

Provides a limited interface between Libxml2 and Fortran using iso_c_binding for DOM-style XML access, along with helper routines for parsing string content into typed Fortran values. Data stored in XML nodes/attributes can be either space-delimited or comma-delimited with newlines to denote 2D arrays.

Authors
Chris Hansen
Date
April 2026

Data Types

interface  oft_xml_free_doc_c
 Free an XML document previously parsed with oft_xml_load_file_c. More...
interface  oft_xml_free_ptr_c
 Free c objects, for example arrays returned by oft_xml_get_elements_c or strings returned by oft_xml_get_content_c. More...
interface  oft_xml_get_attribute_c
 Extract content from an attribute on a given xml node as a string. More...
interface  oft_xml_get_content_c
 Extract content from a given xml node as a string. More...
interface  oft_xml_get_element_c
 Retrieve a pointer to the i-th xml node with a given name inside a parent node. More...
interface  oft_xml_get_elements_c
 Retrieve pointers to all xml nodes with a given name inside a parent node. More...
interface  oft_xml_get_root_c
 Retrieve a pointer to the root element of an xmlDoc object. More...
interface  oft_xml_has_attribute_c
 Test if a given xml node has a given attribute. More...
interface  oft_xml_parse_file_c
 Parse an XML file from a given file path, returning a pointer to the corresponding xmlDoc. More...
type  xml_doc
 XML document wrapper. More...
type  xml_exception
interface  xml_get_element
 Get one or more elements by name from a parent node. More...
type  xml_node
 Libxml2 node wrapper. More...
type  xml_nodelist
 List of XML nodes. More...
interface  xml_read_attribute
 Extract content of a given type from an attribute on an XML node. More...
interface  xml_read_content
 Extract content of a given type from an XML node. More...

Functions/Subroutines

subroutine normalize_string (content_in, content_out)
 Normalize a string by removing leading/trailing whitespace and blank/comment lines.
subroutine oft_xml_free (doc_ptr)
 Free an XML document previously parsed with oft_xml_load.
subroutine oft_xml_get_attr (node, attr_name, content, ierr)
 Extract content from a specified attribute on a given xml node into a Fortran string.
subroutine parse_string_to_doubles (content, output, output_shape, ierr)
 Parse string content into a 1D array of double precision values with shape information.
subroutine parse_string_to_integers (content, output, output_shape, ierr)
 Parse string content into a 1D array of integer values with shape information.
subroutine parse_string_to_logicals (content, output, output_shape, ierr)
 Parse string content into a 1D array of logical values with shape information.
subroutine tokenize_string (content, tokens, ierr)
 Find token boundaries in a string containing comma-delimited and/or newline-delimited values to be parsed into typed Fortran values.
subroutine xml_clear_exceptions ()
 Clear messages from the exception stack.
subroutine xml_extractdataattribute_double (node, attr_name, output, output_shape, iostat)
 Parse a single double precision value from an XML attribute's content.
subroutine xml_extractdataattribute_double1d (node, attr_name, output, output_shape, iostat)
 Parse XML attribute content into a 1D array of double precision values.
subroutine xml_extractdataattribute_double2d (node, attr_name, output, output_shape, iostat)
 Parse XML attribute content into a 2D array of double precision values.
subroutine xml_extractdataattribute_int (node, attr_name, output, output_shape, iostat)
 Parse a single integer value from an XML attribute's content.
subroutine xml_extractdataattribute_int1d (node, attr_name, output, output_shape, iostat)
 Parse XML attribute content into a 1D array of integer values.
subroutine xml_extractdataattribute_int2d (node, attr_name, output, output_shape, iostat)
 Parse XML attribute content into a 2D array of integer values.
subroutine xml_extractdataattribute_logical (node, attr_name, output, output_shape, iostat)
 Parse a single logical value from an XML attribute's content.
subroutine xml_extractdataattribute_logical1d (node, attr_name, output, output_shape, iostat)
 Parse XML attribute content into a 1D array of logical values.
subroutine xml_extractdataattribute_logical2d (node, attr_name, output, output_shape, iostat)
 Parse XML attribute content into a 2D array of logical values.
subroutine xml_extractdataattribute_string (node, attr_name, output, iostat)
 Get content from an XML attribute as a string.
subroutine xml_extractdatacontent_double (node, output, output_shape, iostat)
 Parse a single double precision value from an XML node's content.
subroutine xml_extractdatacontent_double1d (node, output, output_shape, iostat)
 Parse XML content into a 1D array of double precision values.
subroutine xml_extractdatacontent_double2d (node, output, output_shape, iostat)
 Parse XML content into a 2D array of double precision values.
subroutine xml_extractdatacontent_int (node, output, output_shape, iostat)
 Parse XML content into a single integer value.
subroutine xml_extractdatacontent_int1d (node, output, output_shape, iostat)
 Parse XML content into a 1D array of integer values.
subroutine xml_extractdatacontent_int2d (node, output, output_shape, iostat)
 Parse XML content into a 2D array of integer values.
subroutine xml_extractdatacontent_logical (node, output, output_shape, iostat)
 Parse XML content into a single logical value.
subroutine xml_extractdatacontent_logical1d (node, output, output_shape, iostat)
 Parse XML content into a 1D array of logical values.
subroutine xml_extractdatacontent_logical2d (node, output, output_shape, iostat)
 Parse XML content into a 2D array of logical values.
subroutine xml_extractdatacontent_string (node, output, iostat)
 Get content from an XML node as a string.
subroutine xml_get_content (node, content, ierr)
 Extract content from a given xml node into a Fortran string.
subroutine xml_get_element_list (parent, name, elements, error_flag)
 Retrieve all xml nodes with a given name contained within a parent node.
subroutine xml_get_element_single (parent, name, element, error_flag, index)
 Retrieve the i-th xml node with a given name contained within a parent node.
logical function xml_hasattribute (node, attr_name)
 Test if a given xml node has a specified attribute.
logical function xml_node_associated (self)
 Check if an xml_node is associated with a C object.
subroutine xml_parsefile (filepath, doc, ierr)
 Parse an XML file.
subroutine xml_print_exceptions ()
 Print messages from the exception stack.
subroutine xml_set_exception (message)
 Add exception to the exception stack.

Variables

integer(i4) xml_exception_depth = 0
 Exception stack depth (0 if no exceptions).
type(xml_exception), dimension(10) xml_exceptions
 Stack of excepton messages.

Function/Subroutine Documentation

◆ normalize_string()

subroutine normalize_string ( character(len=*), intent(in) content_in,
character(len=:), intent(out), allocatable content_out )

Normalize a string by removing leading/trailing whitespace and blank/comment lines.

Parameters
[in]content_inInput string
[out]content_outOutput string

◆ oft_xml_free()

subroutine oft_xml_free ( type(c_ptr), intent(inout) doc_ptr)

Free an XML document previously parsed with oft_xml_load.

Parameters
[in,out]doc_ptrC pointer to xmlDoc to free

◆ oft_xml_get_attr()

subroutine oft_xml_get_attr ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
character(len=:), intent(out), allocatable content,
integer(i4), intent(out) ierr )

Extract content from a specified attribute on a given xml node into a Fortran string.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]contentOutput string
[out]ierrError flag (0 on success)

◆ parse_string_to_doubles()

subroutine parse_string_to_doubles ( character(len=*), intent(inout) content,
real(r8), dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out) ierr )

Parse string content into a 1D array of double precision values with shape information.

Parameters
[in,out]contentInput string
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]ierrError flag (0 on success)

◆ parse_string_to_integers()

subroutine parse_string_to_integers ( character(len=*), intent(inout) content,
integer(i4), dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out) ierr )

Parse string content into a 1D array of integer values with shape information.

Parameters
[in,out]contentInput string
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]ierrError flag (0 on success)

◆ parse_string_to_logicals()

subroutine parse_string_to_logicals ( character(len=*), intent(inout) content,
logical, dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out) ierr )

Parse string content into a 1D array of logical values with shape information.

Supported values are:

  • True: "true", ".true.", "1", "t" (case-insensitive)
  • False: "false", ".false.", "0", "f" (case-insensitive)
    Parameters
    [in,out]contentInput string
    [out]outputOutput array
    [out]output_shapeShape of the output array (ncols, nrows)
    [out]ierrError flag (0 on success)

◆ tokenize_string()

subroutine tokenize_string ( character(len=*), intent(inout) content,
integer(i4), dimension(:,:,:), intent(out), allocatable tokens,
integer(i4), intent(out) ierr )

Find token boundaries in a string containing comma-delimited and/or newline-delimited values to be parsed into typed Fortran values.

Parameters
[in,out]contentInput string
[out]tokensString tokens as (start,end) indices for each column and row
[out]ierrError flag (0 on success)

◆ xml_clear_exceptions()

subroutine xml_clear_exceptions

Clear messages from the exception stack.

◆ xml_extractdataattribute_double()

subroutine xml_extractdataattribute_double ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
real(r8), intent(out) output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse a single double precision value from an XML attribute's content.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput value
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_double1d()

subroutine xml_extractdataattribute_double1d ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
real(r8), dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML attribute content into a 1D array of double precision values.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_double2d()

subroutine xml_extractdataattribute_double2d ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
real(r8), dimension(:,:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML attribute content into a 2D array of double precision values.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_int()

subroutine xml_extractdataattribute_int ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
integer(i4), intent(out) output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse a single integer value from an XML attribute's content.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput value
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_int1d()

subroutine xml_extractdataattribute_int1d ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
integer(i4), dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML attribute content into a 1D array of integer values.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_int2d()

subroutine xml_extractdataattribute_int2d ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
integer(i4), dimension(:,:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML attribute content into a 2D array of integer values.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_logical()

subroutine xml_extractdataattribute_logical ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
logical, intent(out) output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse a single logical value from an XML attribute's content.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput value
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_logical1d()

subroutine xml_extractdataattribute_logical1d ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
logical, dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML attribute content into a 1D array of logical values.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_logical2d()

subroutine xml_extractdataattribute_logical2d ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
logical, dimension(:,:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML attribute content into a 2D array of logical values.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdataattribute_string()

subroutine xml_extractdataattribute_string ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name,
character(len=:), intent(inout), allocatable output,
integer(i4), intent(out), optional iostat )

Get content from an XML attribute as a string.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name
[in,out]outputOutput string
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_double()

subroutine xml_extractdatacontent_double ( type(xml_node), intent(in) node,
real(r8), intent(out) output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse a single double precision value from an XML node's content.

Parameters
[in]nodeXML node
[out]outputOutput value
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_double1d()

subroutine xml_extractdatacontent_double1d ( type(xml_node), intent(in) node,
real(r8), dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML content into a 1D array of double precision values.

Parameters
[in]nodeXML node
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_double2d()

subroutine xml_extractdatacontent_double2d ( type(xml_node), intent(in) node,
real(r8), dimension(:,:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML content into a 2D array of double precision values.

Parameters
[in]nodeXML node
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_int()

subroutine xml_extractdatacontent_int ( type(xml_node), intent(in) node,
integer(i4), intent(out) output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML content into a single integer value.

Parameters
[in]nodeXML node
[out]outputOutput value
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_int1d()

subroutine xml_extractdatacontent_int1d ( type(xml_node), intent(in) node,
integer(i4), dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML content into a 1D array of integer values.

Parameters
[in]nodeXML node
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_int2d()

subroutine xml_extractdatacontent_int2d ( type(xml_node), intent(in) node,
integer(i4), dimension(:,:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML content into a 2D array of integer values.

Parameters
[in]nodeXML node
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_logical()

subroutine xml_extractdatacontent_logical ( type(xml_node), intent(in) node,
logical, intent(out) output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML content into a single logical value.

Parameters
[in]nodeXML node
[out]outputOutput value
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_logical1d()

subroutine xml_extractdatacontent_logical1d ( type(xml_node), intent(in) node,
logical, dimension(:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML content into a 1D array of logical values.

Parameters
[in]nodeXML node
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_logical2d()

subroutine xml_extractdatacontent_logical2d ( type(xml_node), intent(in) node,
logical, dimension(:,:), intent(out), pointer output,
integer(i4), dimension(2), intent(out), optional output_shape,
integer(i4), intent(out), optional iostat )

Parse XML content into a 2D array of logical values.

Parameters
[in]nodeXML node
[out]outputOutput array
[out]output_shapeShape of the output array (ncols, nrows)
[out]iostatI/O status flag (0 on success)

◆ xml_extractdatacontent_string()

subroutine xml_extractdatacontent_string ( type(xml_node), intent(in) node,
character(len=:), intent(out), allocatable output,
integer(i4), intent(out), optional iostat )

Get content from an XML node as a string.

Parameters
[in]nodeXML node
[out]outputOutput string
[out]iostatI/O status flag (0 on success)

◆ xml_get_content()

subroutine xml_get_content ( type(xml_node), intent(in) node,
character(len=:), intent(out), allocatable content,
integer(i4), intent(out) ierr )

Extract content from a given xml node into a Fortran string.

Parameters
[in]nodeXML node
[out]contentOutput string
[out]ierrError flag (0 on success)

◆ xml_get_element_list()

subroutine xml_get_element_list ( type(xml_node), intent(in) parent,
character(len=*), intent(in) name,
type(xml_nodelist), intent(inout) elements,
integer(i4), intent(out) error_flag )

Retrieve all xml nodes with a given name contained within a parent node.

Parameters
[in]parentParent element
[in]nameElement name to find
[in,out]elementsFound elements
[out]error_flagError flag (0 if successful)

◆ xml_get_element_single()

subroutine xml_get_element_single ( type(xml_node), intent(in) parent,
character(len=*), intent(in) name,
type(xml_node), intent(out) element,
integer(i4), intent(out) error_flag,
integer(i4), intent(in), optional index )

Retrieve the i-th xml node with a given name contained within a parent node.

Parameters
[in]parentParent element
[in]nameElement name to find
[out]elementFound element
[out]error_flagError flag (0 if successful)
[in]indexOptional index, defaults to first matching element

◆ xml_hasattribute()

logical function xml_hasattribute ( type(xml_node), intent(in) node,
character(len=*), intent(in) attr_name )

Test if a given xml node has a specified attribute.

Parameters
[in]nodeXML node
[in]attr_nameAttribute name

◆ xml_node_associated()

logical function xml_node_associated ( class(xml_node), intent(in) self)

Check if an xml_node is associated with a C object.

Parameters
[in]selfXML node

◆ xml_parsefile()

subroutine xml_parsefile ( character(len=*), intent(in) filepath,
type(xml_doc), intent(out) doc,
integer(i4), intent(out) ierr )

Parse an XML file.

Parameters
[in]filepathPath to XML file
[out]docXML document object
[out]ierrError flag (0 on success)

◆ xml_print_exceptions()

subroutine xml_print_exceptions

Print messages from the exception stack.

◆ xml_set_exception()

subroutine xml_set_exception ( character(len=*), intent(in) message)

Add exception to the exception stack.

Parameters
[in]messageException message

Variable Documentation

◆ xml_exception_depth

integer(i4) xml_exception_depth = 0

Exception stack depth (0 if no exceptions).

◆ xml_exceptions

type(xml_exception), dimension(10) xml_exceptions

Stack of excepton messages.