What is the equivalent function of extractDataContent to write data ?

28 views
Skip to first unread message

Francisco

unread,
May 30, 2013, 4:14:14 AM5/30/13
to fox-d...@googlegroups.com
Hi everyone,

I read a xml file with the FoX_dom module and I use the function extractDataContent in order to get the data from a node. Now, I would like to change the data and write them into the node in a similar way to extractDataContent. Does it exist any function to do that?

Thank you in advance.

doc => parseFile("input.xml")

nlist => getElementsByTagname(doc, "interestingElement")

do i = 0, getLength(nlist)-1

np => item(nlist, i) if (value==somethingInteresting) then
call extractDataContent(np, data)
call changeData(data)
call setDataContent(np, data) ! ??????

 end if


end do call destroy(doc)

Andrew Walker

unread,
May 30, 2013, 4:45:58 AM5/30/13
to fox-d...@googlegroups.com
Hi Francisco,

I'm afraid there is nothing quite so simple as setDataContent (maybe there should be) but FoX does have tools to help with this. First, some background. Strictly speaking extractDataContent isn't a DOM function, it is an extra function in FoX_DOM that exists to make the lives of Fortran programmers a bit easer. In pure DOM text nodes only contain textural data but we need some way to turn the string "1" into a Fortran integer (or real, or whatever) so that we can do useful things with it. This is what extractDataContent does, first reading the text node then doing the conversion into whatever datatype "data" happens to be. It's actually little more than a wrapper around the DOM level 3 method getTextContent(). The string to Fortran data type conversion is done by rts() in the FoX_common module.

There is a FoX_common function which does the inverse of rts() called str(). So, all you should need to do to reset the data is:

    call setTextContent(np, str(data))

I've not tested this but it ought to work. You'll need to remember to "use FoX_common" as well as FoX_DOM. I don't think it would be hard to write a setDataContent subroutine (beyond the usual challenge of dealing with m4).

I hope this helps,

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.
 
 

Francisco

unread,
May 30, 2013, 5:07:19 AM5/30/13
to fox-d...@googlegroups.com
Hi Andrew,

Many thanks for the explanation. Your solution sounds good to me but I haven't been able to check it since there is an ambiguous reference to 'getLength' in 'FoX_dom' and 'FoX_common'. Any clue to solve the trouble?

Thank you,
Francisco

Andrew Walker

unread,
May 30, 2013, 5:13:04 AM5/30/13
to fox-d...@googlegroups.com
Hi,

Try "use FoX_common, only : str" in your code instead of just "use FoX_common"

Andrew 

Francisco

unread,
May 30, 2013, 5:17:09 AM5/30/13
to fox-d...@googlegroups.com
Hi Andrew,

It works, you are GOD!

Many thanks,
Francisco
Reply all
Reply to author
Forward
0 new messages