title: Java XML validation Ignore xml elements that do not belong to schema
body: <p>I am working on a Spring Java application that interacts with a SOAP web service. We have enabled strict validation for responses (using an interceptor as shown below), this is required to ensure that already agreed mandatory elements are not missed in response.</p>
  
  <pre><code>public class MyPayloadValidatingInterceptor extends org.springframework.ws.client.support.interceptor.PayloadValidatingInterceptor{
  
      @Override
      protected boolean handleResponseValidationErrors(final MessageContext messageContext,
              final SAXParseException[] errors) {
          for (SAXParseException error : errors) {
              this.logger.error("XML validation error in SOAP response: " + error.getMessage());
          }
          throw new MyResponseValidationException(errors);
      }
  }
  </code></pre>
  
  <p>This is making our application fragile even for small changes to the Schema (new elements in response) at the SOAP web service and forcing client to upgrade the schema even though we don’t use the new elements, application Not forward compatible. 
  I want a way to ignore the unidentified element in the response xml. While having strict validation for the mandatory elements that are part of the current schema that my client application is using.</p>
  
  <p>For example if schema the is </p>
  
  <pre><code>&lt;schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Employee" xmlns:tns="http://www.example.org/Employee"
      elementFormDefault="qualified"&gt;
      &lt;element name="Employee"&gt;
          &lt;complexType&gt;
              &lt;sequence&gt;
                  &lt;element name="EmployeeId" type="string"&gt;&lt;/element&gt;
                  &lt;element name="Name" type="string"&gt;&lt;/element&gt;
                  &lt;element name="SecondName" type="string" minOccurs="0"&gt;&lt;/element&gt;
              &lt;/sequence&gt;
          &lt;/complexType&gt;
      &lt;/element&gt;
  &lt;/schema&gt;
  </code></pre>
  
  <p>For the below xml I want the validation interceptor to ignore the unidentified element, No MyResponseValidationException</p>
  
  <pre><code>&lt;tns:Employee xmlns:tns="http://www.example.org/Employee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/Employee Employee.xsd "&gt;
    &lt;tns:EmployeeId&gt;id&lt;/tns:EmployeeId&gt;
    &lt;tns:Name&gt;Jack&lt;/tns:Name&gt;
    &lt;tns:NewElement&gt;unidentified&lt;/tns:NewElement&gt;
    &lt;tns:SecondName&gt;Second Jack&lt;/tns:SecondName&gt;
  &lt;/tns:Employee&gt;
  </code></pre>
  
  <blockquote>
    <p>Validation ERROR I see is, 
    cvc-complex-type.2.4.a: Invalid content was
    found starting with element 'tns:NewElement'. One of
    '{"<a href="http://www.example.org/Employee" rel="nofollow">http://www.example.org/Employee</a>":SecondName}' is expected.</p>
  </blockquote>
  
  <p>For this xml it should result in MyResponseValidationException</p>
  
  <pre><code>&lt;tns:Employee xmlns:tns="http://www.example.org/Employee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/Employee Employee.xsd "&gt;
    &lt;tns:EmployeeId&gt;tns:EmployeeId&lt;/tns:EmployeeId&gt;
    &lt;!--tns:Name&gt;tns:Name&lt;/tns:Name Mandatory Element missing--&gt;  
    &lt;tns:SecondName&gt;tns:SecondName&lt;/tns:SecondName&gt;
  &lt;/tns:Employee&gt;
  </code></pre>
  
  <blockquote>
    <p>Validation ERROR I see is cvc-complex-type.2.4.a: Invalid content was
    found starting with element 'tns:SecondName'. One of
    '{"<a href="http://www.example.org/Employee" rel="nofollow">http://www.example.org/Employee</a>":Name}' is expected.</p>
  </blockquote>
  
  <p>Can you please suggest best way to differentiate between missing elements and elements that do not belong to schema.</p>
  
  <p>Thanks in advance.</p>