I want to skip the node which contains an error. I use SAXParser
Example XML:
<file>
<person>
<id>1
<name>Jhon</name>
</person>
<person>
<id>2</id>
<name>Julia</name>
</person>
</file>
I use:
SAXParserFactory fact= SAXParserFactory.newInstance();
SAXParser parser= fact.newSAXParser();
MyHandler handler = new MyHandler ();
parser.parse(new File(path), handler);
Example of handler :
public class MyHandler extends org.xml.sax.helpers.DefaultHandler
{
private String message = "";
@Override
public void fatalError(final SAXParseException e)
{
message += "Error : " + e.getMessage();
}
}
I want to skip the error of person with id 1 because we don't have </id>
and continue the execution to person 2 and just save the error message.