6 whitespace = re.compile(
r'\s+')
10 if len(a.attributes) != len(b.attributes):
11 print(
"Different number of attributes")
13 a_atts = [(a.attributes.item(i).name, a.attributes.item(i).value)
for i
in range(len(a.attributes))]
14 b_atts = [(b.attributes.item(i).name, b.attributes.item(i).value)
for i
in range(len(b.attributes))]
18 for i
in range(len(a_atts)):
19 if a_atts[i][0] != b_atts[i][0]:
20 print(
"Different attribute names: %s and %s" % (a_atts[i][0], b_atts[i][0]))
23 if abs(float(a_atts[i][1]) - float(b_atts[i][1])) > 1.0e-9:
24 print(
"Different attribute values: %s and %s" % (a_atts[i][1], b_atts[i][1]))
27 if a_atts[i][1] != b_atts[i][1]:
28 print(
"Different attribute values: %s and %s" % (a_atts[i][1], b_atts[i][1]))
35 a_norm = whitespace.sub(
' ', a)
36 b_norm = whitespace.sub(
' ', b)
37 if a_norm.strip() == b_norm.strip():
39 print(
"Different text values: '%s' and '%s'" % (a, b))
49 if a.nodeType != b.nodeType:
50 print(
"Different node types: %s and %s" % (a, b))
54 if a.nodeType
in [xml.dom.Node.TEXT_NODE,
55 xml.dom.Node.CDATA_SECTION_NODE,
56 xml.dom.Node.COMMENT_NODE]:
60 if a.nodeType != xml.dom.Node.ELEMENT_NODE:
64 if a.nodeName != b.nodeName:
65 print(
"Different element names: %s and %s" % (a.nodeName, b.nodeName))
77 ((a.nodeType
in ignore_nodes)
or
78 (a.nodeType == xml.dom.Node.TEXT_NODE
and whitespace.sub(
'', a.data) ==
""))):
81 ((b.nodeType
in ignore_nodes)
or
82 (b.nodeType == xml.dom.Node.TEXT_NODE
and whitespace.sub(
'', b.data) ==
""))):
97 if isinstance(a, str):
98 return xml_matches(xml.dom.minidom.parseString(a).documentElement, b,
100 if isinstance(b, str):
101 return xml_matches(a, xml.dom.minidom.parseString(b).documentElement,
103 if a.nodeType == xml.dom.Node.DOCUMENT_NODE:
104 return xml_matches(a.documentElement, b, ignore_nodes)
105 if b.nodeType == xml.dom.Node.DOCUMENT_NODE:
106 return xml_matches(a, b.documentElement, ignore_nodes)
109 print(
"Match failed:")
110 a.writexml(sys.stdout)
113 b.writexml(sys.stdout)