Hi everyone,
I would like to catch the exceptions of the subroutine 'serialize', with
call serialize(myDoc, "test.xml", ex). If I don't use the third argument, everything is OK and the xml file is created. However, when I use the third argument, the exception number returned is 999 (it means 'internal FoX error') and no file is created. In order to show the problem, I have modified the dom_example_2.f90 which is included with the source code in the examples directory. What am I doing wrong?
Thank you in advance,
Francisco
program dom_example
use FoX_dom
implicit none
type(DOMException) :: ex
type(Node), pointer :: myDoc, p
type(NodeList), pointer :: parameterList, children
integer :: i, j
real :: energy
! Load in the document
myDoc => parseFile("h2o.xml")
call serialize(myDoc, "test.xml", ex)
print*, getExceptionCode(ex)
!if (getExceptionCode(ex) /= 0) then
! print*, 'problem writing test.xml'
! stop
!end if
! 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