XMLUnit will work, it compares the list references recursively
, also it has option to exclude fields which you do not wish to compare.
String expectedXML = "some xml";
String actualXML = "some xml";
DetailedDiff diff1 = new DetailedDiff(XMLUnit.compareXML(expectedXML, actualXML));
diff1.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
System.out.println("Differences found: " + diff1.getAllDifferences().toString());
RecursiveElementNameAndTextQualifier
Compares all Element and Text nodes in two pieces of XML. Allows elements of complex, deeply nested types that are returned in different orders but have the same content to be recognized as comparable.
Refer this as well.
Also very soon i am going to blog this here.
Generating XML
import com.thoughtworks.xstream.XStream;
public static String writeToXml(Object objectToWrite) {
XStream xstream = new XStream();
return xstream.toXML(objectToWrite);
}
Dependency
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>