xml_file Derived Type

type, public :: xml_file

XML file class.


Inherits

type~~xml_file~~InheritsGraph type~xml_file xml_file type~xml_tag xml_tag type~xml_file->type~xml_tag tag string string type~xml_tag->string tag_name, tag_content, attribute

Components

Type Visibility Attributes Name Initial
type(xml_tag), private, allocatable :: tag(:)

XML tags array.

integer(kind=I4P), private :: nt = 0_I4P

Number of XML tags.


Finalization Procedures

final :: finalize

Free dynamic memory when finalizing.

  • private subroutine finalize(self)

    Free dynamic memory when finalizing.

    Arguments

    Type IntentOptional Attributes Name
    type(xml_file), intent(inout) :: self

    XML file.


Type-Bound Procedures

procedure, public, pass(self) :: add_tag

Add tag to XML file.

  • private elemental subroutine add_tag(self, tag)

    Add tag to XML file.

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(inout) :: self

    XML file.

    type(xml_tag), intent(in) :: tag

    XML tag.

procedure, public, pass(self) :: content

Return tag content of tag named name.

  • private pure function content(self, name)

    Return tag content of tag named name.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(in) :: self

    XML file.

    character(len=*), intent(in) :: name

    Tag name.

    Return Value character(len=:), allocatable

    Tag content.

procedure, public, pass(self) :: delete_tag

Add tag from XML file.

  • private elemental subroutine delete_tag(self, name)

    Delete tag from XML file.

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(inout) :: self

    XML file.

    character(len=*), intent(in) :: name

    XML tag name.

procedure, public, pass(self) :: free

Free dynamic memory.

  • private elemental subroutine free(self)

    Free dynamic memory.

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(inout) :: self

    XML file.

procedure, public, pass(self) :: parse

Parse xml file.

  • private subroutine parse(self, string, filename)

    Parse xml data from string or file. XML data is linearized, a DOM structured is used.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(inout) :: self

    XML file.

    character(len=*), intent(in), optional :: string

    String containing xml data.

    character(len=*), intent(in), optional :: filename

    File name containing xml data.

procedure, public, pass(self) :: stringify

Convert the whole file data into a string.

  • private pure function stringify(self, linearize) result(string)

    Convert the whole file data into a string.

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(in) :: self

    XML file.

    logical, intent(in), optional :: linearize

    Return a "linearized" string of tags without the XML hieararchy.

    Return Value character(len=:), allocatable

    Output string containing the whole xml file.

procedure, private, pass(self) :: add_child

Add child ID to tag children list.

  • private pure subroutine add_child(self, parent_id, child_id)

    Add child ID to tag children list.

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(inout) :: self

    XML file handler.

    integer(kind=I4P), intent(in) :: parent_id

    Parent ID.

    integer(kind=I4P), intent(in) :: child_id

    Child ID.

procedure, private, pass(self) :: parse_from_string

Parse xml data from string.

  • private pure subroutine parse_from_string(self, source_string)

    Parse xml data from a chunk of source string (file stringified for IO on device).

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(inout) :: self

    XML file handler.

    character(len=*), intent(in) :: source_string

    String containing xml data.

procedure, private, pass(self) :: stringify_recursive

Convert recursively tags with children into a string.

  • private pure recursive subroutine stringify_recursive(self, tag, is_done, tag_string)

    Convert recursively tags with children into a string.

    Arguments

    Type IntentOptional Attributes Name
    class(xml_file), intent(in) :: self

    XML file.

    type(xml_tag), intent(in) :: tag

    XML tag with children.

    logical, intent(inout) :: is_done(:)

    List of stringified tags.

    character(len=:), intent(inout), allocatable :: tag_string

    Output string containing the current tag.

Source Code

type, public:: xml_file
   !< XML file class.
   private
   type(xml_tag), allocatable :: tag(:)   !< XML tags array.
   integer(I4P)               :: nt=0_I4P !< Number of XML tags.
   contains
      ! public methods
      procedure, pass(self) :: add_tag    !< Add tag to XML file.
      procedure, pass(self) :: content    !< Return tag content of tag named *name*.
      procedure, pass(self) :: delete_tag !< Add tag from XML file.
      procedure, pass(self) :: free       !< Free dynamic memory.
      procedure, pass(self) :: parse      !< Parse xml file.
      procedure, pass(self) :: stringify  !< Convert the whole file data into a string.
      ! private methods
      procedure, pass(self), private :: add_child           !< Add child ID to tag children list.
      procedure, pass(self), private :: parse_from_string   !< Parse xml data from string.
      procedure, pass(self), private :: stringify_recursive !< Convert recursively tags with children into a string.
      ! operators
      final :: finalize !< Free dynamic memory when finalizing.
endtype xml_file