1 | module m_handlers |
---|
2 | |
---|
3 | use flib_sax |
---|
4 | |
---|
5 | private |
---|
6 | |
---|
7 | ! |
---|
8 | ! A prototype of a specific language processor. |
---|
9 | ! It defines the routines that are called from xml_parser in response |
---|
10 | ! to particular events. |
---|
11 | ! |
---|
12 | ! In this particular example we just print the names of the elements |
---|
13 | ! and the content of the pcdata chunks, as well as any comments, XML |
---|
14 | ! and SGML declarations, etc. |
---|
15 | ! |
---|
16 | ! A module such as this could use "utility routines" to convert pcdata |
---|
17 | ! to numerical arrays, and to populate specific data structures. |
---|
18 | ! |
---|
19 | public :: begin_element_handler, end_element_handler, pcdata_chunk_handler |
---|
20 | public :: comment_handler, xml_declaration_handler, sgml_declaration_handler |
---|
21 | public :: empty_element_handler |
---|
22 | |
---|
23 | CONTAINS !============================================================= |
---|
24 | |
---|
25 | subroutine begin_element_handler(name,attributes) |
---|
26 | character(len=*), intent(in) :: name |
---|
27 | type(dictionary_t), intent(in) :: attributes |
---|
28 | |
---|
29 | write(unit=*,fmt="(2a)") ">>Begin Element: ", name |
---|
30 | write(unit=*,fmt="(a,i2,a)") "--- ", len(attributes), " attributes:" |
---|
31 | call print_dict(attributes) |
---|
32 | end subroutine begin_element_handler |
---|
33 | |
---|
34 | !-------------------------------------------------- |
---|
35 | subroutine end_element_handler(name) |
---|
36 | character(len=*), intent(in) :: name |
---|
37 | |
---|
38 | write(unit=*,fmt="(/,2a)") ">>-------------End Element: ", trim(name) |
---|
39 | |
---|
40 | end subroutine end_element_handler |
---|
41 | |
---|
42 | !-------------------------------------------------- |
---|
43 | subroutine pcdata_chunk_handler(chunk) |
---|
44 | character(len=*), intent(in) :: chunk |
---|
45 | |
---|
46 | write(unit=*,fmt="(a)",advance="no") trim(chunk) |
---|
47 | |
---|
48 | end subroutine pcdata_chunk_handler |
---|
49 | |
---|
50 | !-------------------------------------------------- |
---|
51 | subroutine empty_element_handler(name,attributes) |
---|
52 | character(len=*), intent(in) :: name |
---|
53 | type(dictionary_t), intent(in) :: attributes |
---|
54 | |
---|
55 | write(unit=*,fmt="(2a)") ">>Empty Element: ", name |
---|
56 | write(unit=*,fmt="(a,i2,a)") "--- ", len(attributes), " attributes:" |
---|
57 | call print_dict(attributes) |
---|
58 | write(unit=*,fmt="(2a)") ">>-------------End Empty Element: ", trim(name) |
---|
59 | |
---|
60 | end subroutine empty_element_handler |
---|
61 | |
---|
62 | !-------------------------------------------------- |
---|
63 | subroutine comment_handler(comment) |
---|
64 | character(len=*), intent(in) :: comment |
---|
65 | |
---|
66 | write(unit=*,fmt="(a)") ">>Comment: " |
---|
67 | write(unit=*,fmt="(a)") trim(comment) |
---|
68 | |
---|
69 | end subroutine comment_handler |
---|
70 | |
---|
71 | !-------------------------------------------------- |
---|
72 | subroutine xml_declaration_handler(name,attributes) |
---|
73 | character(len=*), intent(in) :: name |
---|
74 | type(dictionary_t), intent(in) :: attributes |
---|
75 | ! |
---|
76 | ! Same structure as an element tag |
---|
77 | ! |
---|
78 | write(unit=*,fmt="(2a)") ">>XML declaration: ", name |
---|
79 | call print_dict(attributes) |
---|
80 | |
---|
81 | end subroutine xml_declaration_handler |
---|
82 | |
---|
83 | !-------------------------------------------------- |
---|
84 | subroutine sgml_declaration_handler(sgmldecl) |
---|
85 | character(len=*), intent(in) :: sgmldecl |
---|
86 | ! |
---|
87 | write(unit=*,fmt="(a)") ">>SGML declaration: " |
---|
88 | write(unit=*,fmt="(a)") trim(sgmldecl) |
---|
89 | |
---|
90 | end subroutine sgml_declaration_handler |
---|
91 | !-------------------------------------------------- |
---|
92 | |
---|
93 | end module m_handlers |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|