1 | module m_handlers |
---|
2 | use flib_sax |
---|
3 | private |
---|
4 | public :: begin_element, end_element, pcdata_chunk |
---|
5 | ! |
---|
6 | logical, private :: in_item, in_description, in_price |
---|
7 | character(len=40), private :: what, price, currency, id |
---|
8 | ! |
---|
9 | contains !----------------------------------------- |
---|
10 | ! |
---|
11 | subroutine begin_element(name,attributes) |
---|
12 | character(len=*), intent(in) :: name |
---|
13 | type(dictionary_t), intent(in) :: attributes |
---|
14 | |
---|
15 | integer :: status |
---|
16 | |
---|
17 | select case(name) |
---|
18 | case("item") |
---|
19 | in_item = .true. |
---|
20 | call get_value(attributes,"id",id,status) |
---|
21 | |
---|
22 | case("description") |
---|
23 | in_description = .true. |
---|
24 | |
---|
25 | case("price") |
---|
26 | in_price = .true. |
---|
27 | call get_value(attributes,"currency",currency,status) |
---|
28 | |
---|
29 | end select |
---|
30 | |
---|
31 | end subroutine begin_element |
---|
32 | !--------------------------------------------------------------- |
---|
33 | subroutine pcdata_chunk(chunk) |
---|
34 | character(len=*), intent(in) :: chunk |
---|
35 | |
---|
36 | if (in_description) what = chunk |
---|
37 | if (in_price) price = chunk |
---|
38 | |
---|
39 | end subroutine pcdata_chunk |
---|
40 | !--------------------------------------------------------------- |
---|
41 | subroutine end_element(name) |
---|
42 | character(len=*), intent(in) :: name |
---|
43 | |
---|
44 | select case(name) |
---|
45 | case("item") |
---|
46 | in_item = .false. |
---|
47 | write(unit=*,fmt="(5(a,tr1))") trim(id), trim(what), ":", & |
---|
48 | trim(price), trim(currency) |
---|
49 | |
---|
50 | case("description") |
---|
51 | in_description = .false. |
---|
52 | |
---|
53 | case("price") |
---|
54 | in_price = .false. |
---|
55 | |
---|
56 | end select |
---|
57 | |
---|
58 | end subroutine end_element |
---|
59 | !--------------------------------------------------------------- |
---|
60 | end module m_handlers |
---|