[lxml-dev] Proposal: Automatic unique ID generation for each tag or persistend user data for Element

Viksit Gaur vik.list.nutch at gmail.com
Fri Jul 18 21:28:27 CEST 2008


Hello,


Dr R. Sanderson wrote:
> Hi all,
> 
> I have a similar requirement, and approached it in the following way:
> 
> While processing the elements of interest, generate the full path of the 
> element, hash() it and put it into a dictionary.
> 
> eg:
> 
> tree = node.getroottree()
> elems = node.xpath('//p')
> info = {}
> for e in elems:
>    eid = abs(hash(tree.getpath(e)))
>    # processing here...
> 

:) Ah, I've been needing to do exactly the same thing - except I wasn't 
using hashes, just numbers to denote IDs! Thanks for the tip.

Cheers
Viksit


More information about the lxml-dev mailing list