Re: lxml, comparing nodes

2008-07-25 Thread code_berzerker
If document order doesn't matter, try sorting the elements of each level in the two documents by some arbitrary deterministic key, such as (tag name, text, attr count, whatever), and then compare them in order, instead of trying to find matches in multiple passes. itertools.groupby() might be

Re: lxml, comparing nodes

2008-07-25 Thread Stefan Behnel
code_berzerker wrote: If document order doesn't matter, try sorting the elements of each level in the two documents by some arbitrary deterministic key, such as (tag name, text, attr count, whatever), and then compare them in order, instead of trying to find matches in multiple passes.

Re: lxml, comparing nodes

2008-07-25 Thread code_berzerker
Not in your code. Stefan Not sure what you mean, but I tested and so far every document with the same order of elements had number of comparisons equal to number of nodes. -- http://mail.python.org/mailman/listinfo/python-list

Re: lxml, comparing nodes

2008-07-25 Thread Stefan Behnel
code_berzerker wrote: Not in your code. Stefan Not sure what you mean, but I tested and so far every document with the same order of elements had number of comparisons equal to number of nodes. Sorry, missed the let2.remove(foundEl) line. Stefan --

Re: lxml, comparing nodes

2008-07-24 Thread code_berzerker
off the top of my head (untested):   def equal(a, b): ...     if a.tag != b.tag or a.attrib != b.attrib: ...         return False ...     if a.text != b.text or a.tail != b.tail: ...         return False ...     if len(a) != len(b): ...         return False ...     if any(not equal(a, b)

Re: lxml, comparing nodes

2008-07-24 Thread Stefan Behnel
code_berzerker wrote: Thanks for help. Thats inspiring, tho not exactly what I need, coz ignoring document order is requirement (ignoring changes in order of different siblings of the same type, etc). I plan to try something like that: def xmlCmp(xmlStr1, xmlStr2): et1 =

lxml, comparing nodes

2008-07-23 Thread code_berzerker
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. 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).

Re: lxml, comparing nodes

2008-07-23 Thread Sebastian lunar Wiesner
code_berzerker [EMAIL PROTECTED]: 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. 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

Re: lxml, comparing nodes

2008-07-23 Thread code_berzerker
On Jul 23, 6:29 pm, Stefan Behnel [EMAIL PROTECTED] wrote: 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

Re: lxml, comparing nodes

2008-07-23 Thread Fredrik Lundh
code_berzerker wrote: 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