Phanx,
I tested in game and without no surprise (because you write it :-) works like a charm
Without the XML part I am also able to understand the code much better
I attach here the code packed as addon if someone else wants to use (it is really very handy).
If Phanx don't mind to make an addon herself and don't mind too the fact she wrote it all I can also publish and mantain it (or at least try to
.
Thanks again Phanx.