From: Ted B. <te...@et...> - 2001-09-02 03:25:09
|
I'm trying to build a simple XML editor targetted at a specific use. I am displaying the xml node names as elements in a JTree and have implemented a TreeModel to accomplish this. The nodes in the tree model extract relevant info from a JDOM Element object passed to their fromXML method after creation. This method populates the callee node's child list and calls each child's fromXML method. From the print out generated by the fromXML method, it appears that everything is working, but when the process is complete another print shows that something has gone dramatically wrong. print generated during population: [Element: <nodehandler/>] [Element: <group_atts/>] [Element: <nodehandler/>] [Element: <file/>] [Element: <nodehandler/>] [Element: <file/>] [Element: <nodehandler/>] [Element: <file/>] print of tree root element's 'children' list after population of the TreeModel: [group_atts, file, nodehandler, file, nodehandler, file, nodehandler] Relevant code snippet from InstallSetTreeModel: def fromXML( self, node, space='' ): print space,node self.name = node.name for n in node.children: f = InstallSetTreeModel( self ) f.fromXML( n, space+' ') self.children.append( f ) Obviously *something* isn't right. What am I doing wrong? node is a JDOM Element object, node.children returns a List of child Elements. Once this model is placed in a tree, each node in the tree has for children each node in the tree. It's a *huge* circular reference bug, and I haven't been able to find it. The code is part of a project that will allow java/jython applications to download updates from a website. The whole shebang will be publicly available when i'm done too, if that's any sort of carrot. :) I can post the whole file if it would help, I just wanted to avoid spamming the list right off. ted |
From: Ype K. <yk...@xs...> - 2001-09-02 09:43:06
|
Ted, >I'm trying to build a simple XML editor targetted at a specific use. I am >displaying the xml node names as elements in a JTree and have implemented a >TreeModel to accomplish this. > >The nodes in the tree model extract relevant info from a JDOM Element object >passed to their fromXML method after creation. This method populates the >callee node's child list and calls each child's fromXML method. > >From the print out generated by the fromXML method, it appears that >everything is working, but when the process is complete another print shows >that something has gone dramatically wrong. > >print generated during population: > > [Element: <nodehandler/>] > [Element: <group_atts/>] > [Element: <nodehandler/>] > [Element: <file/>] > [Element: <nodehandler/>] > [Element: <file/>] > [Element: <nodehandler/>] > [Element: <file/>] > >print of tree root element's 'children' list after population of the >TreeModel: > >[group_atts, file, nodehandler, file, nodehandler, file, nodehandler] > >Relevant code snippet from InstallSetTreeModel: > > def fromXML( self, node, space='' ): > print space,node > self.name = node.name > for n in node.children: > f = InstallSetTreeModel( self ) > f.fromXML( n, space+' ') > self.children.append( f ) > >Obviously *something* isn't right. What am I doing wrong? node is a JDOM >Element object, node.children returns a List of child Elements. Once this >model is placed in a tree, each node in the tree has for children each node in the tree. It's a *huge* circular reference bug, and I haven't been able >to find it. First off: I am not familiar with JDOM and XML, so what follows might be quite non relevant. It seems to me that your problem might be caused by f = InstallSetTreeModel( self ) returning self instead of a newly created InstallSetTreeModel. Supposing this is a constructor call, why is self passed? In case you want a new child node (f is appended to self.children lateron), you might introduce a separate method for creating a new child node. > >The code is part of a project that will allow java/jython applications to >download updates from a website. The whole shebang will be publicly >available when i'm done too, if that's any sort of carrot. :) > >I can post the whole file if it would help, I just wanted to avoid spamming >the list right off. > >ted > >_______________________________________________ >Jython-users mailing list >Jyt...@li... >https://lists.sourceforge.net/lists/listinfo/jython-users |
From: Ted B. <te...@et...> - 2001-09-02 11:15:27
|
On Sunday 02 September 2001 03:49, Ype Kingma wrote: > > First off: I am not familiar with JDOM and XML, so what follows > might be quite non relevant. Not a problem. Actually, I think the issue is more likely a python-related mistake that I'm making. > It seems to me that your problem might be caused by > > f = InstallSetTreeModel( self ) > > returning self instead of a newly created InstallSetTreeModel. > Supposing this is a constructor call, why is self passed? > In case you want a new child node (f is appended to self.children > lateron), you might introduce a separate method for creating > a new child node. > The argument is used to create a reference-to-parent in the new object, like so: def __init__( self, parent=None ): self.parent = parent which is used to determine the topmost object in the tree. ted |
From: <bc...@wo...> - 2001-09-05 19:39:39
|
[Ted Berg] >I'm trying to build a simple XML editor targetted at a specific use. I am >displaying the xml node names as elements in a JTree and have implemented a >TreeModel to accomplish this. > >The nodes in the tree model extract relevant info from a JDOM Element object >passed to their fromXML method after creation. This method populates the >callee node's child list and calls each child's fromXML method. > >From the print out generated by the fromXML method, it appears that >everything is working, but when the process is complete another print shows >that something has gone dramatically wrong. > >print generated during population: > > [Element: <nodehandler/>] > [Element: <group_atts/>] > [Element: <nodehandler/>] > [Element: <file/>] > [Element: <nodehandler/>] > [Element: <file/>] > [Element: <nodehandler/>] > [Element: <file/>] > >print of tree root element's 'children' list after population of the >TreeModel: > >[group_atts, file, nodehandler, file, nodehandler, file, nodehandler] > >Relevant code snippet from InstallSetTreeModel: > > def fromXML( self, node, space='' ): > print space,node > self.name = node.name > for n in node.children: > f = InstallSetTreeModel( self ) > f.fromXML( n, space+' ') > self.children.append( f ) > >Obviously *something* isn't right. It seems right to me. Did you expect it to write >[nodehandler, group_atts, nodehandler, file, nodehandler, file, nodehandler, file] instead? Then try to add nodes to the the list at the position where you have your print statement. >The code is part of a project that will allow java/jython applications to >download updates from a website. The whole shebang will be publicly >available when i'm done too, if that's any sort of carrot. :) > >I can post the whole file if it would help, I just wanted to avoid spamming >the list right off. Posting an url to the source is the way to go. regards, finn |