How to remove invalid XML elements
<p>I have a XML file and its XSD schema.
I am able to validate the XML file and implement a custom org.xml.sax.ErrorHandler like the following:</p>

<pre><code>class MyErrorHandler implements ErrorHandler{
  ...
  @Override
  public void warning(SAXParseException exception) throws SAXException {
    System.out.println("Line: " + exception.getLineNumber() + ") " + exception.getMessage() + exception);
    warnings++;
  }
...
}
</code></pre>

<p>Is it possible to actually manipulate the element causing the exception, for example by removing it from the XML file?</p>

<p>Two notes:</p>

<ul>
<li>the XML manipulation doesn't need to be in-place, i.e. I can produce a new file with the failing elements removed;</li>
<li>best would be to be able to also get the parent element of the one causing the exception, so that I can decide whether to remove the parent altogether.</li>
</ul>

<p>Also just a suggestion on which direction to follow in order to solve the problem is appreciated. Thanks!</p>