~sbjesse/+junk/xmlin

« back to all changes in this revision

Viewing changes to xmlin.py

  • Committer: Jesse Zhang
  • Date: 2009-02-02 15:39:04 UTC
  • Revision ID: jesse@jesse-cq20-20090202153904-i5jev9u2jrtcsb97
passed TestIgnorableWS and TestLonelyRoot

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
        return hash((attr_hash, child_hash))
18
18
    raise IndexError("Unexpected node type : %d" % node.nodeType)
19
19
 
 
20
def notIgnorable(node):
 
21
    return not (node.nodeType == dom.Node.TEXT_NODE and \
 
22
            node.data.strip() == '')
 
23
 
20
24
def xmlin(tree1, tree2):
21
 
    msgs2 = set(hash(c) for c in tree2.childNodes)
22
 
    msgs1 = set(hash(c) for c in tree1.childNodes)
 
25
    msgs2 = set(hash(c) for c in tree2.childNodes if notIgnorable(c))
 
26
    msgs1 = set(hash(c) for c in tree1.childNodes if notIgnorable(c))
23
27
    return msgs1 <= msgs2
24
28
 
25
29
minidom.Node.__hash__ = xml_hash