lxml, comparing nodes

Stefan Behnel stefan_ml at behnel.de
Wed Jul 23 18:29:22 CEST 2008

code_berzerker wrote:
> I'd like to know if there is any built in mechanism in lxml that lets
> you check equality of two nodes from separate documents.

No, because, as you state yourself, equality is not something that everyone
defines the same way.

> I'd like it
> to ignore attribute order and so on. It would be even better if there
> was built in method for checking equality of whole documents (ignoring
> document order). Please let me know if you know of such method or
> existing scipt. I dont like reinventing the wheel :)

Your requirements for a single Element are simple enough to write it in three
to five lines of Python code (depending on your definition of equality).
Checking this equality recursively is another two to three lines. Not complex
enough to be considered a wheel in the first place.


More information about the Python-list mailing list