1 | program item_context |
---|
2 | use flib_xpath |
---|
3 | |
---|
4 | type(xml_t) :: fxml, context |
---|
5 | |
---|
6 | integer :: status |
---|
7 | character(len=100) :: what, price, currency |
---|
8 | type(dictionary_t) :: attributes |
---|
9 | |
---|
10 | call open_xmlfile("inventory.xml",fxml,status) |
---|
11 | ! |
---|
12 | do |
---|
13 | call mark_node(fxml,path="//item",status=status) |
---|
14 | if (status < 0) exit ! No more items |
---|
15 | context = fxml ! Save item context |
---|
16 | ! |
---|
17 | ! Search relative to context |
---|
18 | ! |
---|
19 | call get_node(fxml,path="price", & |
---|
20 | attributes=attributes,pcdata=price,status=status) |
---|
21 | call get_value(attributes,"currency",currency,status) |
---|
22 | if (status /= 0) stop "missing currency attribute!" |
---|
23 | ! |
---|
24 | ! Rewind to beginning of context |
---|
25 | ! |
---|
26 | fxml = context |
---|
27 | call sync_xmlfile(fxml,status) |
---|
28 | ! |
---|
29 | ! Search relative to context |
---|
30 | ! |
---|
31 | call get_node(fxml,path="description",pcdata=what,status=status) |
---|
32 | write(unit=*,fmt="(6a)") "Appliance: ", trim(what), & |
---|
33 | ". Price: ", trim(price), " ", trim(currency) |
---|
34 | enddo |
---|
35 | end program item_context |
---|