-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathdom_example_4.f90
42 lines (33 loc) · 1.2 KB
/
dom_example_4.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
program dom_example_4
! Example of error handling from the DOM interface
!
! Note the need to check the value of the iostat as well
! as ex. If the iostat optional argument is present and
! the file cannot be found that is the variable that gets
! set in the parseFile function. If iostat is not present
! in this case FoX will abort itself reporting that it
! "Cannot open file". This kind of error does not get
! attached to the DOMException.
!
! If the file exists but is not well-formed XML the error
! should be reported in the DOMException. One oddity to note
! is that if ex is not present but ios is, you may end up
! with a FoX error code in ios. That only happens if the file
! exists but it not well-formed XML.
use FoX_dom
implicit none
type(Node), pointer :: myDoc
type(DOMException) :: ex
integer :: ios
myDoc => parseFile("h2o.xml", iostat=ios, ex=ex)
if (ios.ne.0) then
print*, "Problem reading file. iostat was ", ios
stop
elseif (inException(ex)) then
print*,"DOM Parse error ", getExceptionCode(ex)
stop
else
print*, "Not in exception and file read OK"
endif
! Do something with myDoc
end program dom_example_4