Hi there,
As if I haven't posted enough to the parsed-xml-dev list yet, here some more..
What I want to have is an ability to keep a reference to a unique
node in a document, without using a reference to the node itself
directly. This because I want to store these references in say a
session. By using such a reference I can recognize whether I've
run into a node before and take action (such as pull things from
the cache, or render it differently as I've selected that node
for special operations in the GUI, etc)
With XMLDocument, URLs to nodes were stable enough to make this possible.
I'd simply get the absolute_url to some node and I had my reference.
Unfortunately ParsedXML URLs to nodes are very unstable with respect
to changes to the DOM, so that won't work.
So, I've been pondering a way to get this for ParsedXML. One way would be
to change the way URLs work to be more stable towards changes, but how?
One simple way is to simply keep a reference to the node directly.
Unfortunately that seems hard to do for sessions and would cause a lot
of growth of the ZODB if references are kept there. Nodes may never
get garbage collected.
Another way is to give each node that is created a unique id. For that
we'd need to change the DOM in some places and we'll have to carry the
unique id around, but that'd certainly be possible.
A hybrid approach I tried but didn't get far with is to keep a weak
value dictionary. The key is some unique id that a manager class can
assign, and the value is the weak ref to the node. This way, if a node
goes away, it won't be in the dictionary anymore either. Unfortunately
I get:
TypeError: 'ExplicitAcquirerWrapper' objects are not weakly referencable
when I try to put nodes in a WeakValueDictionary, so this seems to be
a no-go.
Yet another way would be to exploit some properties of the ZODB to get
a unique id to the node object. Since nodes aren't persistent objects
directly, I guess that won't work, right?
Anyway, some feedback on this matter would be welcome. I'm also sending
a cc to the zope-xml list to get some more discussion on this, hopefully.
Perhaps it's a use case others have run into before.
(should I move this kind of discussion in general to the zope-xml list?
Sometimes I don't know where I should be posting my stuff)
Regards,
Martijn
As if I haven't posted enough to the parsed-xml-dev list yet, here some more..
What I want to have is an ability to keep a reference to a unique
node in a document, without using a reference to the node itself
directly. This because I want to store these references in say a
session. By using such a reference I can recognize whether I've
run into a node before and take action (such as pull things from
the cache, or render it differently as I've selected that node
for special operations in the GUI, etc)
With XMLDocument, URLs to nodes were stable enough to make this possible.
I'd simply get the absolute_url to some node and I had my reference.
Unfortunately ParsedXML URLs to nodes are very unstable with respect
to changes to the DOM, so that won't work.
So, I've been pondering a way to get this for ParsedXML. One way would be
to change the way URLs work to be more stable towards changes, but how?
One simple way is to simply keep a reference to the node directly.
Unfortunately that seems hard to do for sessions and would cause a lot
of growth of the ZODB if references are kept there. Nodes may never
get garbage collected.
Another way is to give each node that is created a unique id. For that
we'd need to change the DOM in some places and we'll have to carry the
unique id around, but that'd certainly be possible.
A hybrid approach I tried but didn't get far with is to keep a weak
value dictionary. The key is some unique id that a manager class can
assign, and the value is the weak ref to the node. This way, if a node
goes away, it won't be in the dictionary anymore either. Unfortunately
I get:
TypeError: 'ExplicitAcquirerWrapper' objects are not weakly referencable
when I try to put nodes in a WeakValueDictionary, so this seems to be
a no-go.
Yet another way would be to exploit some properties of the ZODB to get
a unique id to the node object. Since nodes aren't persistent objects
directly, I guess that won't work, right?
Anyway, some feedback on this matter would be welcome. I'm also sending
a cc to the zope-xml list to get some more discussion on this, hopefully.
Perhaps it's a use case others have run into before.
(should I move this kind of discussion in general to the zope-xml list?
Sometimes I don't know where I should be posting my stuff)
Regards,
Martijn