[1960] | 1 | program self |
---|
| 2 | use flib_xpath |
---|
| 3 | ! |
---|
| 4 | ! Example of re-scanning of an element |
---|
| 5 | ! |
---|
| 6 | type(xml_t) :: fxml |
---|
| 7 | type(dictionary_t) :: attributes |
---|
| 8 | |
---|
| 9 | integer :: status |
---|
| 10 | character(len=100) :: id, currency, price |
---|
| 11 | |
---|
| 12 | call open_xmlfile("inventory.xml",fxml,status) |
---|
| 13 | ! |
---|
| 14 | do |
---|
| 15 | call mark_node(fxml,path="//item",status=status) |
---|
| 16 | if (status < 0) exit |
---|
| 17 | ! |
---|
| 18 | ! Pretend we forgot to get the id attribute... |
---|
| 19 | ! |
---|
| 20 | call get_node(fxml,path=".",attributes=attributes,status=status) |
---|
| 21 | if (status < 0) exit |
---|
| 22 | call get_value(attributes,"id",id,status) |
---|
| 23 | if (status /= 0) stop "missing id attribute!" |
---|
| 24 | print *, "Id: ", trim(id) |
---|
| 25 | ! |
---|
| 26 | ! Now perform a relative search in two stages: |
---|
| 27 | ! First the attributes... |
---|
| 28 | ! |
---|
| 29 | call get_node(fxml,path="price",attributes=attributes,status=status) |
---|
| 30 | if (status < 0) exit |
---|
| 31 | call get_value(attributes,"currency",currency,status) |
---|
| 32 | if (status /= 0) stop "missing currency attribute!" |
---|
| 33 | print *, "Currency: ", trim(id) |
---|
| 34 | |
---|
| 35 | ! And then the pcdata. Note that "." refers now to the /item/price |
---|
| 36 | ! element, since fxml has been running through the file and we |
---|
| 37 | ! have not saved any context to get back to. |
---|
| 38 | ! |
---|
| 39 | call get_node(fxml,path=".",pcdata=price,status=status) |
---|
| 40 | if (status /= 0) stop "error in retrieving price data" |
---|
| 41 | print *, "Price: ", trim(price) |
---|
| 42 | enddo |
---|
| 43 | end program self |
---|