And this might too, because whitespace around the tags or swapped attribute order might screw around with the text output:

return $xml1->asXml() == $xml2->asXml();

Technically, even if this was to work (i.e. check that they have the same structure, not the same resource identifier), but the order of the XML documents were different, then it should still fail - XML documents have order.

So I wrote a function which will allow you to check two XML documents and make sure they have the same structure, attributes and children, but in any order (below). Use the optional parameter "$text_strict" to test explicitly for all leading and trailing whitespace.