parse Subroutine

private elemental subroutine parse(self, source, tstart, tend)

Type Bound

xml_tag

Arguments

Type IntentOptional Attributes Name
class(xml_tag), intent(inout) :: self
character(len=*), intent(in) :: source
integer(kind=I4P), intent(out), optional :: tstart
integer(kind=I4P), intent(out), optional :: tend

Calls

proc~~parse~~CallsGraph proc~parse xml_tag%parse proc~get xml_tag%get proc~parse->proc~get proc~is_allocated string%is_allocated proc~parse->proc~is_allocated proc~parse_attributes_names xml_tag%parse_attributes_names proc~parse->proc~parse_attributes_names proc~parse_tag_name xml_tag%parse_tag_name proc~parse->proc~parse_tag_name proc~get_attributes xml_tag%get_attributes proc~get->proc~get_attributes proc~get_value xml_tag%get_value proc~get->proc~get_value proc~alloc_attributes xml_tag%alloc_attributes proc~parse_attributes_names->proc~alloc_attributes

Called by

proc~~parse~~CalledByGraph proc~parse xml_tag%parse proc~parse_from_string xml_file%parse_from_string proc~parse_from_string->proc~parse proc~search xml_tag%search proc~search->proc~parse program~create_tag create_tag program~create_tag->proc~parse proc~get_content xml_tag%get_content proc~get_content->proc~search proc~parse~2 xml_file%parse proc~parse~2->proc~parse_from_string proc~content xml_file%content proc~content->proc~get_content program~delete_tag delete_tag program~delete_tag->proc~parse~2 program~parse_file_simple parse_file_simple program~parse_file_simple->proc~parse~2 program~parse_string_simple parse_string_simple program~parse_string_simple->proc~parse~2 program~write_tag write_tag program~write_tag->proc~parse~2

Source Code

  elemental subroutine parse(self, source, tstart, tend)
  !< Parse the tag contained into a source string.
  !<
  !< It is assumed that the first tag contained into the source string is parsed, the others eventually present are omitted.
  !< Valid syntax are:
  !< + `<tag_name att1="att1 val" att2="att2 val"...>...</tag_name>`
  !< + `<tag_name att1="att1 val" att2="att2 val".../>`
  !< @note Inside the attributes value the symbols `<` and `>` are not allowed.
  class(xml_tag),         intent(inout) :: self      !< XML tag.
  character(*),           intent(in)    :: source    !< String containing the input.
  integer(I4P), optional, intent(out)   :: tstart    !< Starting index of tag inside the string.
  integer(I4P), optional, intent(out)   :: tend      !< Ending index of tag inside the string.
  integer(I4P)                          :: tstartd   !< Starting index of tag inside the string.
  integer(I4P)                          :: tendd     !< Ending index of tag inside the string.

  tstartd = 0
  tendd   = 0
  call self%parse_tag_name(source=source, tstart=tstartd, tend=tendd)
  if (self%tag_name%is_allocated()) then
    if (index(string=source(tstartd:tendd), substring='=')>0) call self%parse_attributes_names(source=source(tstartd:tendd))
    if (index(string=source, substring='</'//self%tag_name//'>')>0) &
      tendd = index(string=source, substring='</'//self%tag_name//'>') + len('</'//self%tag_name//'>') - 1
    call self%get(source=source(tstartd:tendd))
  endif
  if (present(tstart)) tstart = tstartd
  if (present(tend  )) tend   = tendd
  endsubroutine parse