Parse the tag name contained into a string.
It is assumed that the first tag contained into the source 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.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(xml_tag), | intent(inout) | :: | self |
XML tag. |
||
character(len=*), | intent(in) | :: | source |
String containing the input. |
||
integer(kind=I4P), | intent(out), | optional | :: | tstart |
Starting index of tag inside the source. |
|
integer(kind=I4P), | intent(out), | optional | :: | tend |
Ending index of tag inside the source. |
elemental subroutine parse_tag_name(self, source, tstart, tend) !< Parse the tag name contained into a string. !< !< It is assumed that the first tag contained into the source 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 source. integer(I4P), optional, intent(out) :: tend !< Ending index of tag inside the source. integer(I4P) :: tstartd !< Starting index of tag inside the source. integer(I4P) :: tendd !< Ending index of tag inside the source. character(len=1) :: c1 !< Dummy string for parsing file. character(len=:), allocatable :: c2 !< Dummy string for parsing file. integer(I4P) :: c !< Counter. integer(I4P) :: s !< Counter. call self%tag_name%free tstartd = 0 tendd = 0 c = 1 Tag_Search: do while(c<=len(source)) c1 = source(c:c) if (c1=='<'.and.source(c+1:c+1)/='/') then tstartd = c c2 = c1 Tag_Name: do while(c<len(source)) c = c + 1 ; c1 = source(c:c) c2 = c2//c1 if (c1=='>') then tendd = c exit Tag_Name endif enddo Tag_Name s = index(string=c2, substring=' ') if (s>0) then ! there are attributes self%tag_name = c2(2:s-1) else if (index(string=c2, substring='/>')>0) then ! self closing tag self%tag_name = c2(2:len(c2)-2) else self%tag_name = c2(2:len(c2)-1) endif endif exit Tag_Search endif c = c + 1 enddo Tag_Search if (present(tstart)) tstart = tstartd if (present(tend )) tend = tendd endsubroutine parse_tag_name