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