Problem catching serialize exceptions

已查看 23 次
跳至第一个未读帖子

Francisco

未读,
2013年5月30日 08:54:442013/5/30
收件人 fox-d...@googlegroups.com
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

Andrew Walker

未读,
2013年6月5日 14:53:192013/6/5
收件人 fox-d...@googlegroups.com
Hi Francisco,

This turns out to be a bug in FoX - we were checking that the exception was "expected" (specifically, was a namespace error) and forgot that the no error case is an expected condition. Anyway, I've fixed it in my github repository and added a couple of new test cases. You will need to grab a new version of the code from: 

Cheers,

Andrew





--
You received this message because you are subscribed to the Google Groups "FoX-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fox-discuss...@googlegroups.com.
To post to this group, send email to fox-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/fox-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
--
Andrew Walker
School of Earth Sciences
University of Bristol

Francisco

未读,
2013年6月12日 06:10:522013/6/12
收件人 fox-d...@googlegroups.com
Hi Andrew,

Thank you so much for the update, it works properly.

Cheers,
Francisco
回复全部
回复作者
转发
0 个新帖子