get_attributes Subroutine

private elemental subroutine get_attributes(self, source)

Arguments

TypeIntentOptionalAttributesName
class(xml_tag), intent(inout) :: self
character, intent(in) :: source

Contents

Source Code


Source Code

  elemental subroutine get_attributes(self, source)
  !< Get the attributes values from source after tag_name and attributes names have been set.
  class(xml_tag), intent(inout) :: self   !< XML tag.
  character(*),   intent(in)    :: source !< String containing data.
  integer                       :: a      !< Counter.
  integer                       :: c1     !< Counter.
  integer                       :: c2     !< Counter.

  if (index(string=source, substring='<'//self%tag_name)>0) then
    if (self%attributes_number>0) then ! parsing attributes
      do a=1, self%attributes_number
        c1 = index(string=source, substring=self%attribute(1, a)//'="') + self%attribute(1, a)%len() + 2
        if (c1>self%attribute(1, a)%len() + 2) then
          c2 = index(string=source(c1:), substring='"')
          if (c2>0) then
            self%attribute(2, a) = source(c1:c1+c2-2)
          else
            call self%attribute(2, a)%free
          endif
        else
          call self%attribute(2, a)%free
        endif
      enddo
    endif
  endif
  endsubroutine get_attributes