logo       

could not continue after fatal error--need urgent help: msg#00038

Subject: could not continue after fatal error--need urgent help

Hi friends,
I?m facing problem in validating xml file against a schema with Xerces 2.9.0. I am new to this xml validation field.
My Problem is my DOM Parser do not log all the well Formed errors. It only log one fatal error that is first from the bottom of the xml file. If I introduced two well formed error then it only reports last error (first from the bottom of the xml doc)But I need it to log all the fatal errors. Setting feature continue-after-fatal-error did not work.
The (relevant portion of the) XML document follows:(with two well formed errors)***************
<?xml version="1.0" encoding="UTF-8"?>
<rootDirMapping>
     <rootDir>AppData</rootDir>
     <mappingFile>MappingFiles</mappingFile>
     <schemaFile>SchemaFiles<schemaFile>
     <validationHierarchy>1hierarchy<validationHierarchy>
     <database>database</database>
</rootDirMapping>
The (relevant portion of the) XML schema follows:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="rootDirMapping">
          <xs:complexType>
               <xs:sequence>
                    <xs:element name="rootDir" type="xs:string" />
                    <xs:element name="mappingFile" type="xs:string" />
                    <xs:element name="schemaFile" type="xs:string" />
                    <xs:element name="validationHierarchy" type="xs:string" />
                    <xs:element name="database" type="xs:string" />
               </xs:sequence>
          </xs:complexType>
     </xs:element>
</xs:schema>
*************************************************************
The (relevant portion of the) Java Code follows:
public static boolean validateWithSchema(String XMLFile, String Schema){
           boolean result = true;
           long startTime = System.currentTimeMillis();
           // Instantiate the DOM parser.
           DOMParser parser = new DOMParser();
           // set the features
           try{
           parser.setFeature("http://xml.org/sax/features/namespaces",true);
           parser.setFeature("http://xml.org/sax/features/validation",true);
           parser.setFeature("http://apache.org/xml/features/validation/schema",true);
           parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
           parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
           parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",Schema);
           // myErrorHandler is a descendant of ErrorHandler, it should be set here to be able to catch parse errors
           forgivingErrorHandler hndl = new forgivingErrorHandler();
           parser.setErrorHandler(hndl);
           } catch (SAXNotSupportedException ex){
                System.out.println("SAXNotSupportedException Exception");
           } catch (SAXNotRecognizedException ex){
                System.out.println("SAXNotRecognizedException Exception");
           }
           // parse the xml file, the errorhandler class has callbacks,
           // so those will be called automatically there is a parse error
           try{
                parser.parse(XMLFile);
              //System.out.println("Parsed Successfully by DOM Parser");
           } catch (org.xml.sax.SAXException ex){
                System.out.println("SAXException Exception");
              ex.printStackTrace();
           } catch (java.io.IOException ex){
                System.out.println("IOException Exception");
           }
          return result;
          }
The (relevant portion of the) Java Code for Error Handler follows:
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class forgivingErrorHandler implements org.xml.sax.ErrorHandler {
     
     public forgivingErrorHandler() {}
     public void error(org.xml.sax.SAXParseException err) throws SAXException {
          FileWriter fstream;
          try {
               String fs="D:\\WORKSPACE\\xmlValidation\\ExceptionLogs\\Errors.txt";
               fstream = new FileWriter(fs,true);
               PrintWriter out = new PrintWriter(fstream);
               out.write("Exception at:"+err.getLineNumber()+"***"+err.getMessage()+"\n\n\n");
               out.close();
          } catch (IOException e) {
               e.printStackTrace();
          }
          
     }

     public void fatalError(org.xml.sax.SAXParseException fe) throws SAXException {
          FileWriter fstream;
          try {
               String fs="D:\\WORKSPACE\\xmlValidation\\ExceptionLogs\\FatalErrors.txt";
               fstream = new FileWriter(fs,true);
               PrintWriter out = new PrintWriter(fstream);
               out.write("Exception at:"+fe.getLineNumber()+"***"+fe.getMessage()+"\n\n\n");
               out.close();
          } catch (IOException e) {
               e.printStackTrace();
          }
          
     }

     public void warning(org.xml.sax.SAXParseException war) throws SAXException {
          FileWriter fstream;
          try {
               fstream = new FileWriter("D:\\WORKSPACE\\xmlValidation\\ExceptionLogs\\Warnings.txt",true);
               PrintWriter out = new PrintWriter(fstream);
               out.write("Exception at:"+war.getLineNumber()+"***"+war.getMessage()+"\n\n\n");
               out.close();
          } catch (IOException e) {
               System.out.println("Here are we in the Warning section....");
               e.printStackTrace();
          }
          
     }
     
     
}
Unfortunately, when I try to validate the above XML document against the Schema, it throws errors as I explained above? only one fatal error.
Errors that I got*****************************
Exception at:8***The element type "validationHierarchy" must be terminated by the matching end-tag "</validationHierarchy>".

Exception at:8***The end-tag for element type "validationHierarchy" must end with a '>' delimiter.

Exception at:9***XML document structures must start and end within the same entity.

Exception at:-1***Premature end of file.
*************************
I have put xml-apis.jar, xercesImpl.jar, serializer.jar, resolver.jar at build path.
After several long searches in the web, I could not find any solution.
Please help me or please let me know where to find an answer.
Kind regards and please apologize if this question already appeared in the
mailing list, but -- again -- all I found/read about this problem didn't
suffice.


Vineet Rajput
Software Engineer
Snap-On Business Solution
Logix Techno Park,
Noida,INDIA



pms
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe