DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17330>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17330

DocumentBuilder behaves incorrect after parse error

           Summary: DocumentBuilder behaves incorrect after parse error
           Product: Xerces2-J
           Version: 2.3.0
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Other
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


I am using the same DocumentBuilder to parse serveral XMLs, one after each 
other. I also have my own ErrorHandler, which throws an exception on errors and 
fatal errors.

If I parse a correct XML, then an incorrect (schema violation throws a parse 
error) XML and then the first XML again, then I get the same parse errors for 
the first XML, which is correct!

This happens with Xerces 2.2.0 and 2.3.0. It only happens, if my ErrorHandler 
throws an exception on errors.

Is it illegal to parse several documents using the same DocumentBuilder?


This is my code:

    DocumentBuilderFactory dbf;
    DocumentBuilder db;
    Document d;
    
    dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(true); 
    dbf.setAttribute("http://apache.org/xml/features/validation/dynamic";,
                    new Boolean(true));
    dbf.setAttribute("http://apache.org/xml/features/validation/schema";, 
                     new Boolean(true));
    db = dbf.newDocumentBuilder();
    db.setErrorHandler(new XmlErrorHandler());

    d = db.parse(new File("AngebotDefinition.xml"));
    
    try {
      d = db.parse(new File("PlvPosDefinition.xml"));
    } catch(Exception ex) {
      System.out.println("Catching expected exception.");
    }
    
    d = db.parse(new File("AngebotDefinition.xml"));


------------------------------------------------------------

  public static class XmlErrorHandler implements org.xml.sax.ErrorHandler
  {    
    public void warning(org.xml.sax.SAXParseException sAXParseException) throws 
org.xml.sax.SAXException {
    }
    
    public void error(org.xml.sax.SAXParseException sAXParseException) throws 
org.xml.sax.SAXException {
      throw new org.xml.sax.SAXException("Error at " + 
sAXParseException.getLineNumber() + "/" + sAXParseException.getColumnNumber()  
+ ": " + sAXParseException.getMessage());
    }
    
    public void fatalError(org.xml.sax.SAXParseException sAXParseException) 
throws org.xml.sax.SAXException {
      throw new org.xml.sax.SAXException("Fatal Error at " + 
sAXParseException.getLineNumber() + "/" + sAXParseException.getColumnNumber()  
+ ": " + sAXParseException.getMessage());
    }    
  } // XmlErrorHandler


Attaching XMLs and their schemas as repro.zip.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to