XML verifying

I have a problem described as following: Let a XML document called D1, now, if a have another XML document called D2, I need a mechanism for verifying that D2 is derived from D1, in other words how we can verify (tool, mechanism, algorithm, etc) that D2 respect the DTD (Document Type Definition) of D1.