Well, without the use of a library, I would - employ a depth first search on the source document, associate an xpath with each leaf encountered and place that xpath with it's associated value on a stack. (most likely some xpath custom class for path and value). (the option of a dictionary is there too. :) ). Once the depth first search is completed, I would pop each element of the stack off, execute the X-path on the destination document, and once a disparity in the xpath values are encountered - consider the documents unequal.
Just a theoretical suggestion.