foxy_test_write_tag Program

Uses

  • program~~foxy_test_write_tag~~UsesGraph program~foxy_test_write_tag foxy_test_write_tag module~foxy foxy program~foxy_test_write_tag->module~foxy module~foxy_xml_file foxy_xml_file module~foxy->module~foxy_xml_file module~foxy_xml_tag foxy_xml_tag module~foxy->module~foxy_xml_tag penf penf module~foxy->penf module~foxy_xml_file->module~foxy_xml_tag module~foxy_xml_file->penf module~foxy_xml_tag->penf stringifor stringifor module~foxy_xml_tag->stringifor

FoXy test.


Calls

program~~foxy_test_write_tag~~CallsGraph program~foxy_test_write_tag foxy_test_write_tag proc~parse~2 xml_file%parse program~foxy_test_write_tag->proc~parse~2 proc~stringify~2 xml_file%stringify program~foxy_test_write_tag->proc~stringify~2 proc~load_file_as_stream load_file_as_stream proc~parse~2->proc~load_file_as_stream proc~parse_from_string xml_file%parse_from_string proc~parse~2->proc~parse_from_string proc~stringify xml_tag%stringify proc~stringify~2->proc~stringify proc~stringify_recursive xml_file%stringify_recursive proc~stringify~2->proc~stringify_recursive proc~add_child xml_file%add_child proc~parse_from_string->proc~add_child proc~add_tag xml_file%add_tag proc~parse_from_string->proc~add_tag proc~get_tag_content get_tag_content proc~parse_from_string->proc~get_tag_content proc~parse_tag_name~2 parse_tag_name proc~parse_from_string->proc~parse_tag_name~2 proc~set xml_tag%set proc~parse_from_string->proc~set chars chars proc~stringify->chars is_allocated is_allocated proc~stringify->is_allocated proc~end_tag xml_tag%end_tag proc~stringify->proc~end_tag proc~self_closing_tag xml_tag%self_closing_tag proc~stringify->proc~self_closing_tag proc~start_tag xml_tag%start_tag proc~stringify->proc~start_tag proc~stringify_recursive->proc~stringify proc~stringify_recursive->proc~stringify_recursive proc~add_child_id xml_tag%add_child_id proc~add_child->proc~add_child_id proc~find_matching_end_tag find_matching_end_tag proc~get_tag_content->proc~find_matching_end_tag proc~add_multiple_attributes xml_tag%add_multiple_attributes proc~set->proc~add_multiple_attributes proc~add_single_attribute xml_tag%add_single_attribute proc~set->proc~add_single_attribute proc~add_stream_attributes xml_tag%add_stream_attributes proc~set->proc~add_stream_attributes proc~add_multiple_attributes->proc~add_single_attribute proc~alloc_attributes xml_tag%alloc_attributes proc~add_single_attribute->proc~alloc_attributes proc~add_stream_attributes->proc~add_single_attribute fill fill proc~add_stream_attributes->fill partition partition proc~add_stream_attributes->partition slice slice proc~add_stream_attributes->slice

Variables

Type Attributes Name Initial
character(len=:), allocatable :: source

String containing the source XML data.

character(len=:), allocatable :: parsed

String containing the parsed XML data.

type(xml_tag) :: a_tag

XML tag handler.

type(xml_file) :: xfile

XML file handler.

integer :: xunit

XML file unit.

logical :: test_passed(3)

List of passed tests.


Source Code

program foxy_test_write_tag
!< FoXy test.
use foxy

implicit none
character(len=:), allocatable :: source         !< String containing the source XML data.
character(len=:), allocatable :: parsed         !< String containing the parsed XML data.
type(xml_tag)                 :: a_tag          !< XML tag handler.
type(xml_file)                :: xfile          !< XML file handler.
integer                       :: xunit          !< XML file unit.
logical                       :: test_passed(3) !< List of passed tests.

test_passed = .false.

print "(A)", 'source'
source = '<first x="1" y="c" z="2">lorem ipsum...</first>'
print "(A)", source
a_tag = xml_tag(name='first', content='lorem ipsum...', attributes=reshape([['x', '1'], ['y', 'c'], ['z', '2']], [2,3]))
open(newunit=xunit, file='parse_file_simple.xml', access='STREAM', form='UNFORMATTED', status='REPLACE')
print "(A)", 'write tag'
call a_tag%write(unit=xunit, form='unformatted')
close(unit=xunit)
call xfile%parse(filename='parse_file_simple.xml')
print "(A)", 'parsed data'
parsed = xfile%stringify()
print "(A)", parsed
test_passed(1) = trim(source)==trim(parsed)
print "(A,L1)", 'Is parsed data correct? ', test_passed(1)

print "(A)", 'source'
source = '<first x="1" y="c" z="2">'//new_line('a')//'  lorem ipsum...'//new_line('a')//'</first>'
print "(A)", source
a_tag = xml_tag(name='first', content='lorem ipsum...', attributes=reshape([['x', '1'], ['y', 'c'], ['z', '2']], [2,3]))
open(newunit=xunit, file='parse_file_simple.xml', access='STREAM', form='UNFORMATTED', status='REPLACE')
print "(A)", 'write tag'
call a_tag%write(unit=xunit, form='unformatted', is_indented=.true., is_content_indented=.true.)
close(unit=xunit)
call xfile%parse(filename='parse_file_simple.xml')
print "(A)", 'parsed data'
parsed = xfile%stringify()
print "(A)", parsed
test_passed(2) = trim(source)==trim(parsed)
print "(A,L1)", 'Is parsed data correct? ', test_passed(2)

open(newunit=xunit, file='parse_file_simple.xml', access='STREAM', form='UNFORMATTED', status='REPLACE')
print "(A)", 'write tag'
call a_tag%write(unit=xunit, form='unformatted', is_indented=.true., only_start=.true., end_record=new_line('a'))
call a_tag%write(unit=xunit, form='unformatted', is_content_indented=.true., only_content=.true., end_record=new_line('a'))
call a_tag%write(unit=xunit, form='unformatted', is_indented=.true., only_end=.true.)
close(unit=xunit)
call xfile%parse(filename='parse_file_simple.xml')
print "(A)", 'parsed data'
parsed = xfile%stringify()
print "(A)", parsed
test_passed(3) = trim(source)==trim(parsed)
print "(A,L1)", 'Is parsed data correct? ', test_passed(3)

open(newunit=xunit, file='parse_file_simple.xml')
close(unit=xunit, status='DELETE')

print "(A,L1)", new_line('a')//'Are all tests passed? ', all(test_passed)
endprogram foxy_test_write_tag