title: XML Unit - Using custom element selectors on different xml elements
body: <p>I'm having a problem comparing various elements in my xml document with XMLUnit (2.2.1). In my document there are several xml elements and I want to 
  know, whether they differ from each other. However, I don't want to compare all xml elements the same way. Sometimes I just want to compare them by their name.In other cases I want to compare them by name and attribute or name and text.</p>
  
  <p>Here is an example (see the comments)</p>
  
  <p>Control</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ROOT&gt;
     &lt;LANGUAGES&gt;
        &lt;!-- Compare LANGUAGE by Name and Attribute --&gt;
        &lt;LANGUAGE VALUE="DE" /&gt;
        &lt;LANGUAGE VALUE="EN" /&gt;
        &lt;LANGUAGE VALUE="IT" /&gt;
        &lt;LANGUAGE VALUE="FR" /&gt;
     &lt;/LANGUAGES&gt;
     &lt;CODES&gt;
        &lt;!-- Compare CODE by Name and Text --&gt;
        &lt;CODE&gt;10000-1&lt;/CODE&gt;
        &lt;CODE&gt;20000-2&lt;/CODE&gt;
        &lt;CODE&gt;30000-3&lt;/CODE&gt;
        &lt;CODE&gt;40000-4&lt;/CODE&gt;
     &lt;/CODES&gt;
     &lt;CONTACT&gt; &lt;!-- Compare CONTACT and Children just by Name --&gt;
        &lt;FIRSTNAME&gt;Max&lt;/FIRSTNAME&gt;
        &lt;SURNAME&gt;Mustermann&lt;/SURNAME&gt;
     &lt;/CONTACT&gt;
  &lt;/ROOT&gt;
  </code></pre>
  
  <p>Test:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ROOT&gt;
     &lt;LANGUAGES&gt;
        &lt;!-- Compare LANGUAGE by Name and Attribute --&gt;
        &lt;LANGUAGE VALUE="DE" /&gt;
        &lt;LANGUAGE VALUE="FR" /&gt;
     &lt;/LANGUAGES&gt;
     &lt;CODES&gt;
        &lt;!-- Compare CODE by Name and Text --&gt;
        &lt;CODE&gt;20000-2&lt;/CODE&gt;
        &lt;CODE&gt;40000-4&lt;/CODE&gt;
     &lt;/CODES&gt;
     &lt;CONTACT&gt; &lt;!-- Compare CONTACT and Children by Name --&gt;
        &lt;FIRSTNAME&gt;Tim&lt;/FIRSTNAME&gt;
        &lt;SURNAME&gt;Mustermann&lt;/SURNAME&gt;
     &lt;/CONTACT&gt;
  &lt;/ROOT&gt;
  </code></pre>
  
  <p>I tried ElementSelectors in combination with ElementSelectors.conditionalBuilder (<a href="https://github.com/xmlunit/user-guide/wiki/SelectingNodes#conditional-elementselectors" rel="nofollow noreferrer">https://github.com/xmlunit/user-guide/wiki/SelectingNodes#conditional-elementselectors</a>)  to only apply an ElementSelector on a specific element (whenElementIsNamed). Maybe this isn't the right approach for what I want to achieve.</p>
  
  <p>This is my code I use for testing:</p>
  
  <pre><code>public void xmlDiff() {
      String control = getControlDocument(); //
      String test = getTestDocument(); //
      Diff myDiff = DiffBuilder.compare(control)//
              .withTest(test) //
              .ignoreWhitespace() //
              .ignoreComments() //
              .checkForSimilar() //
              .withNodeMatcher(new DefaultNodeMatcher(partialElementSelector("LANGUAGE", ElementSelectors.byNameAndAllAttributes), partialElementSelector("CODE",ElementSelectors.byNameAndText), ElementSelectors.byName)) //
              .build();
      assertThat(myDiff.hasDifferences()).isTrue(); // 
  }
  
      private ElementSelector partialElementSelector(final String expectedName, final ElementSelector elementSelector) {
          return ElementSelectors.conditionalBuilder().whenElementIsNamed(expectedName).thenUse(elementSelector).build();
      }
  </code></pre>
  
  <p>What I actually need is the information, that two LANGUAGEs (EN,IT) and two CODEs (10000-1,30000-3) have been removed (not replaced) and FIRSTNAME changed.</p>
  
  <p>How can I get those information, with or without XML Unit (DiffBuilder)? </p>
  
  <p>Thank you for your help!</p>