I need to check if an XML document contains a given XML DOM subtree. I only need to ensure that all the elements and attributes from this subtree are present in the document. However, there can be more elements or attributes in the subtree of the document that matches the given subtree for comparison. And I want them to be skipped from the comparison.
So far I have implemented my own solution which finds a subtree represented by Node class in the given XML document. This Node class contains only the attributes necessary for comparison - element name, text content, list of child nodes and map of attributes. I have implemented my own class and not used org.w3c.dom.Node because it is just too big containing many unnecessary attributes for my test scenario. The subtree represented by the root Node element is iterated one element after another and each its subtree is searched in the given XML document using XPath until the whole tree is checked or any subtree is not found.
This solution works well only when I need to check if the subtree is present there or not. However, I use this to check large configuration files that are often changed and it is quite difficult to find the exact place where the change occurred. That is why I think about using some existing solution which has better output and allows to easily see the differences. Unfortunately, I have not been able to find anything matching my criteria.
Is there any tool that allows this? I have heard about XMLUnit and have a quick look at it but I am not sure if it is capable of finding a subtree in a document ignoring any other elements or attributes. Can you show me an example how to do this in XMLUnit if it is possible?