-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathdom_example_2.f90
45 lines (37 loc) · 1.35 KB
/
dom_example_2.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
43
44
45
program dom_example
use FoX_dom
implicit none
type(Node), pointer :: myDoc, p
type(NodeList), pointer :: parameterList, children
integer :: i, j
real :: energy
! Load in the document
myDoc => parseFile("h2o.xml")
! Find all the parameters:
parameterList => getElementsByTagNameNS(myDoc, &
"http://www.xml-cml.org/schema", "parameter")
print*, "Found ", getLength(parameterList), " parameters."
! Loop over the parameter list. Note that the DOM
! counts from zero, not from one.
do i = 0, getLength(parameterList)-1
p => item(parameterList, i)
! Check for the existence of the attribute we're looking for
if (hasAttribute(p, "name")) then
if (getAttribute(p, "name")=="DM.EnergyTolerance") then
! The energy is in the text node which is the child of the <scalar> element under this node ...
! Check all the children of the node for the <scalar> element.
children => getChildNodes(p)
do j = 0, getLength(children)-1
p => item(children, j)
if (getLocalName(p) =="scalar") then
! This is the scalar node whose child we want:
call extractDataContent(p, energy)
print*, "Energy Tolerance is ", energy
endif
enddo
endif
endif
enddo
! Clear up all allocated memory
call destroy(myDoc)
end program dom_example