Prev: RESULT: comp.lang.tcl.announce will be removed
Next: Need to develop some kind of GUI designer (sigh)
From: drscrypt on 2 Mar 2010 10:57 I am seeing a strange bug with tdom. I had a working script to open a file, parse it, get its root element and do processing on it. I decided to put the opening and parsing part into a proc and return the xml doc or root element to the caller. However, when the caller receives the doc element, it is no longer valid. If I do all the processing in the proc it still works but if I decide to return any parsed xml doc reference to the caller, it fails. It seems that tdom expects all processing to happen at the same level and when the proc returns, tdom somehow destroys the dom object it created. is this the way it is supposed to be? DrS
From: Alexandre Ferrieux on 2 Mar 2010 11:49 On Mar 2, 4:57 pm, drscr...(a)gmail.com wrote: > I am seeing a strange bug with tdom. I had a working script to open a > file, parse it, get its root element and do processing on it. I decided > to put the opening and parsing part into a proc and return the xml doc > or root element to the caller. However, when the caller receives the > doc element, it is no longer valid. If I do all the processing in the > proc it still works but if I decide to return any parsed xml doc > reference to the caller, it fails. > > It seems that tdom expects all processing to happen at the same level > and when the proc returns, tdom somehow destroys the dom object it > created. is this the way it is supposed to be? Sounds weird in our EIAS world :} If it could happen in 8.6 HEAD (don't know if tdom can) I'd display [::tcl::unsupported::representation $parsed] before and after function return (look at the refcount). -Alex
From: drscrypt on 2 Mar 2010 12:10 Alexandre Ferrieux wrote: > Sounds weird in our EIAS world :} > If it could happen in 8.6 HEAD (don't know if tdom can) I'd display > [::tcl::unsupported::representation $parsed] before and after function > return (look at the refcount). > No, this is on 8.4 with different subversions. Here is some code that might help you to reproduce it including a sample xml file: package req tdom package req Tk proc get_x {fname} { set xfile [open $fname r] dom parse [read $xfile] xdoc close $xfile puts "xml doc: [$xdoc childNodes]" return $xdoc } set f [tk_getOpenFile] set xdoc [get_x $f] puts "xml doc: [$xdoc childNodes]" This is a sample xml file: <?xml version="1.0" encoding="UTF-8" ?> <employee> <name>Jane</name> <salary>30000</salary> </employee> > -Alex >
From: Alan Grunwald on 2 Mar 2010 17:12 drscrypt(a)gmail.com wrote: > Alexandre Ferrieux wrote: >> Sounds weird in our EIAS world :} >> If it could happen in 8.6 HEAD (don't know if tdom can) I'd display >> [::tcl::unsupported::representation $parsed] before and after function >> return (look at the refcount). >> > > > No, this is on 8.4 with different subversions. Here is some code that > might help you to reproduce it including a sample xml file: > > > package req tdom > package req Tk > > proc get_x {fname} { > set xfile [open $fname r] > dom parse [read $xfile] xdoc > close $xfile > puts "xml doc: [$xdoc childNodes]" > return $xdoc > } > > > set f [tk_getOpenFile] > > set xdoc [get_x $f] > puts "xml doc: [$xdoc childNodes]" > > > > This is a sample xml file: > <?xml version="1.0" encoding="UTF-8" ?> > <employee> > <name>Jane</name> > <salary>30000</salary> > </employee> > > > > > > > >> -Alex >> I think this is expected and documented behaviour. If you do dom parse $data doc then doc is deleted and tidied up when it goes out of scope. If you do set doc [dom parse $data] then you need to clean up after yourself. So, if you change your proc to proc get_x {fname} { set xfile [open $fname r] set xdoc [dom parse [read $xfile] close $xfile puts "xml doc: [$xdoc childnodes] return $xdoc } all should be well. For the sake of tidiness, you should also $xdoc delete when you've finished with it. Alan
From: drscrypt on 2 Mar 2010 19:08 Alan Grunwald wrote: > > I think this is expected and documented behaviour. If you do > > dom parse $data doc > > then doc is deleted and tidied up when it goes out of scope. If you do > > set doc [dom parse $data] > Interesting difference between the two usage patterns. The explicit set works. Thanks. DrS
|
Next
|
Last
Pages: 1 2 Prev: RESULT: comp.lang.tcl.announce will be removed Next: Need to develop some kind of GUI designer (sigh) |