New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
i.item_context2.f90 in vendors/XMLF90/current/doc/Tutorial/xpath – NEMO

source: vendors/XMLF90/current/doc/Tutorial/xpath/i.item_context2.f90 @ 1960

Last change on this file since 1960 was 1960, checked in by flavoni, 14 years ago

importing XMLF90 r_53 vendor

File size: 1.5 KB
Line 
1module m_aux
2
3use flib_xpath
4private
5public :: get_item_info
6
7CONTAINS
8
9subroutine get_item_info(context,what,price,currency)
10
11type(xml_t), intent(in)       :: context
12character(len=*), intent(out) :: what, price, currency
13
14!
15! Local variables
16!
17type(xml_t)        :: ff
18integer            :: status
19type(dictionary_t) :: attributes
20
21  !
22  ! context is read-only, so make a copy and sync just in case
23  !
24  ff = context
25  call sync_xmlfile(ff,status) 
26  !
27  call get_node(ff,path="price", &
28                attributes=attributes,pcdata=price,status=status)
29  call get_value(attributes,"currency",currency,status)
30  if (status /= 0) stop "missing currency attribute!"
31  !
32  ! Rewind to beginning of context
33  !
34  ff = context
35  call sync_xmlfile(ff,status) 
36  !
37  call get_node(ff,path="description",pcdata=what,status=status)
38
39end subroutine get_item_info
40
41end module m_aux
42!-----------------------------------------------------------------
43!-----------------------------------------------------------------
44program item_context2
45use flib_xpath
46use m_aux          ! To access the subroutine
47
48type(xml_t) :: fxml
49
50integer  :: status
51character(len=100)  :: what, price, currency
52
53call open_xmlfile("inventory.xml",fxml,status)
54!
55do
56  call mark_node(fxml,path="//item",status=status)
57  if (status /= 0)   exit      ! No more items
58  call get_item_info(fxml,what,price,currency)
59  write(unit=*,fmt="(6a)") "Appliance: ", trim(what), &
60                            ". Price: ", trim(price), " ", trim(currency)
61  call sync_xmlfile(fxml,status)
62enddo
63end program item_context2
Note: See TracBrowser for help on using the repository browser.