27 character,
parameter ::
nl = achar(10)
57 character(len=maxlen) :: name
63 character(len=maxlen) :: attvalue
72 character(len=maxlen) :: name
82 generic :: add_chardata => add_chardata_string, add_chardata_printer
88 character(len=maxlen),
allocatable :: header_lines(:)
109 character(len=maxlen) :: text
135 integer,
intent(in) :: indent
136 integer,
intent(in) :: fid
157 integer,
intent(in) :: indent
158 integer,
intent(in) :: fid
179 integer,
intent(in) :: indent
180 integer,
intent(in) :: fid
182 if (.not.
associated(self%item))
then
187 call self%item%write(indent, fid)
190 if (
associated(self%next))
call self%next%write(indent, fid)
198 if (.not.
associated(self%item))
then
203 if (
associated(self%next))
then
204 call self%next%delete()
205 deallocate (self%next)
209 call self%item%delete()
210 deallocate (self%item)
220 if (.not.
associated(self%item))
then
224 if (
associated(self%next))
then
225 new_cont => self%next%new_content()
228 new_cont => self%next
236 character(len=*),
intent(in) :: line
239 character(len=maxlen),
allocatable :: tmp(:)
241 if (
allocated(self%header_lines))
then
242 nl =
size(self%header_lines)
243 allocate (tmp(nl + 1))
244 tmp(1:nl) = self%header_lines(1:nl)
250 tmp(nl + 1) = trim(line)
252 call move_alloc(from=tmp, to=self%header_lines)
259 character(len=*),
intent(in) :: name
263 if (
allocated(self%root))
then
267 self%root%name = trim(name)
270 new_root => self%root
277 character(len=*),
intent(in) :: fname
282 open (file=fname, status=
'replace', form=
'formatted', newunit=fid)
285 if (
allocated(self%header_lines))
then
286 do i = lbound(self%header_lines, 1), ubound(self%header_lines, 1)
287 write (fid,
'(a)') trim(self%header_lines(i))
292 if (
allocated(self%root))
then
293 call self%root%write(0, fid)
306 if (
allocated(self%header_lines))
deallocate (self%header_lines)
309 if (
allocated(self%root))
then
310 call self%root%delete()
311 deallocate (self%root)
319 integer,
intent(in) :: indent
320 integer,
intent(in) :: fid
322 logical :: empty_element
324 character(len=2) :: closing
327 empty_element = .not.
allocated(self%content)
330 if (
allocated(self%attributes))
then
331 na =
size(self%attributes)
337 if (empty_element)
then
345 write (fid,
'(*(a))') &
346 repeat(
' ', indent)//
'<'//trim(self%name), &
347 (
' '//self%attributes(i)%to_string(), i=1, na), &
350 write (fid,
'(*(a))') &
351 repeat(
' ', indent)//
'<'//trim(self%name), &
355 if (.not. empty_element)
then
356 call self%content%write(indent + 2, fid)
357 write (fid,
'(a)') repeat(
' ', indent)//
'</'//trim(self%name)//
'>'
367 if (
allocated(self%attributes))
then
368 deallocate (self%attributes)
372 if (
allocated(self%content))
then
373 call self%content%delete()
374 deallocate (self%content)
382 character(len=*),
intent(in) :: name
383 character(len=*),
intent(in) :: attvalue
388 if (
allocated(self%attributes))
then
389 na =
size(self%attributes)
390 allocate (tmp(na + 1))
391 tmp(1:na) = self%attributes(1:na)
397 tmp(na + 1)%name = name
398 tmp(na + 1)%attvalue = attvalue
400 call move_alloc(from=tmp, to=self%attributes)
407 character(len=*),
intent(in) :: string
412 if (.not.
allocated(self%content))
then
413 allocate (self%content)
414 new_cont => self%content
416 new_cont => self%content%new_content()
425 select type (new_cdata => new_item%chardata)
429 new_cdata%text = adjustl(string)
444 if (.not.
allocated(self%content))
then
445 allocate (self%content)
446 new_cont => self%content
448 new_cont => self%content%new_content()
456 allocate (new_item%chardata, source=printer)
465 character(len=*),
intent(in) :: name
471 if (.not.
allocated(self%content))
then
472 allocate (self%content)
473 new_cont => self%content
475 new_cont => self%content%new_content()
490 integer,
intent(in) :: indent
491 integer,
intent(in) :: fid
493 call self%chardata%print_text(indent, fid)
501 if (
allocated(self%chardata))
then
502 call self%chardata%delete()
503 deallocate (self%chardata)
511 integer,
intent(in) :: indent
512 integer,
intent(in) :: fid
516 write (fid,
'(*(a))') (
' ', i=1, indent), trim(self%text)
525 print *, storage_size(self)
533 character(len=:),
allocatable :: s
537 char_len = len_trim(self%name) + len_trim(self%attvalue) + 3
538 allocate (
character(len=char_len) :: s)
540 s = trim(self%name)//
"='"//trim(self%attvalue)//
"'"
Delete XML item (deallocate everything)
Write XML content to file.
Facilities for constructing an XML tree and printing it to file.
type(sll_t_xml_element) function, pointer t_xml_document__new_element(self, name)
subroutine t_xml_document__add_header_line(self, line)
subroutine t_xml_element__add_chardata_printer(self, printer)
recursive subroutine t_xml_element__delete(self)
subroutine t_xml_chardata__delete(self)
recursive subroutine t_xml_content__delete(self)
subroutine t_xml_document__delete(self)
subroutine t_xml_chardata__write(self, indent, fid)
type(sll_t_xml_element) function, pointer t_xml_element__new_element(self, name)
pure character(len=:) function, allocatable attribute_name_val_string(self)
recursive subroutine t_xml_element__write(self, indent, fid)
subroutine t_xml_element__add_attribute(self, name, attvalue)
subroutine default_print_text(self, indent, fid)
recursive type(t_xml_content) function, pointer t_xml_content__new_content(self)
subroutine t_xml_document__write(self, fname)
subroutine t_xml_element__add_chardata_string(self, string)
subroutine default_delete(self)
integer, parameter maxlen
recursive subroutine t_xml_content__write(self, indent, fid)
XML abstract class: generic printer for writing chardata to file.
Base class for all the XML entities which can appear in content.
XML type: default printer for writing chardata.
XML type: linked list of XML entities, used in element content.