Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 44828 invoked from network); 1 Mar 2004 16:32:53 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 1 Mar 2004 16:32:53 -0000 Received: (qmail 21507 invoked by uid 500); 1 Mar 2004 16:32:41 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 21474 invoked by uid 500); 1 Mar 2004 16:32:40 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 21457 invoked from network); 1 Mar 2004 16:32:40 -0000 Received: from unknown (HELO mallaury.noc.nerim.net) (62.4.17.101) by daedalus.apache.org with SMTP; 1 Mar 2004 16:32:40 -0000 Received: from webmail.nerim.net (mirana.nerim.net [62.4.16.87]) by mallaury.noc.nerim.net (Postfix) with SMTP id E4DC562E01 for ; Mon, 1 Mar 2004 17:32:40 +0100 (CET) Received: from 159.50.101.9 (SquirrelMail authenticated user ldewavrin) by webmail.nerim.net with HTTP; Mon, 1 Mar 2004 17:32:42 +0100 (CET) Message-ID: <55384.159.50.101.9.1078158762.squirrel@webmail.nerim.net> Date: Mon, 1 Mar 2004 17:32:42 +0100 (CET) Subject: [Digester] Validating a XML schema problem From: ldewavrin@nerim.net To: commons-user@jakarta.apache.org User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi, I load an XML file with Apache digester and I have a strange behaviour with XML schema validation. I have enabled XML schema validation and provided a XML input file with a syntax error in it => The syntax error is well detected by Apache Digester: ######################################################################## 2554 [main] ERROR org.apache.commons.digester.Digester - Parse Error at line 5 column 36: cvc-enumeration-valid: Value 'GLOBA' is not facet-valid with respect to enumeration '[GLOBAL, PERL5]'. org.xml.sax.SAXParseException: cvc-enumeration-valid: Value 'GLOBA' is not facet-valid with respect to enumeration '[GLOBAL, PERL5]' at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) ######################################################################## But no exception SAXParseException is raised as I thought it would be. I was expecting to catch a SAXParseException and actually it doesn't happen. The stack trace seems to confirm to a SAXParseException should be raised but it not the case. I have enabled XML schema validation with the following lines: digester.setFeature("http://xml.org/sax/features/validation", true); digester.setFeature("http://apache.org/xml/features/validation/schema",true); digester.setFeature("http://xml.org/sax/features/namespaces", true); The XML parser is Xerces-j 2.4.0 with JAXP 1.2.3 Here's the source code: import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Stack; import org.apache.commons.digester.Digester; import org.xml.sax.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.xml.parsers.ParserConfigurationException; public class XMLLogInputSource implements LogInputSource { private File xmlfile; private List loginputs = new ArrayList(); private Stack LogInputsStack=new Stack(); protected final Log logger = LogFactory.getLog(getClass()); public XMLLogInputSource(File file) { xmlfile = file; } public LogInput[] getLogInputs() throws LogInputSourceException { if (xmlfile == null) { logger.error("Can not process a null xml file"); throw new LogInputSourceException("Error during xml input source processing"); } feedLogInputs(); return (LogInput[]) loginputs.toArray(new LogInput[0]); } private void feedLogInputs() throws LogInputSourceException { try { logger.info("Beginning processing of the xml input file"); Digester digester = new Digester(); // We load the DTD by ourself, cause the DTD is included in our jar EntityResolver xmlentityresolver = new XMLEntityResolver(); digester.setEntityResolver(xmlentityresolver); // Set DTD validation on digester.setValidating(true); // turn on XML schema validation digester.setFeature("http://xml.org/sax/features/validation", true); digester.setFeature("http://apache.org/xml/features/validation/schema",true); digester.setFeature("http://xml.org/sax/features/namespaces", true); digester.push(this); digester.addCallMethod("loginputs/dir", "setLogInputDir", 1); digester.addCallParam("loginputs/dir", 0, "name"); digester.addCallMethod("loginputs/dir/logpattern", "addLogInput", 3); digester.addCallParam("loginputs/dir/logpattern", 0, "num"); digester.addCallParam("loginputs/dir/logpattern", 1, "type"); digester.addCallParam("loginputs/dir/logpattern", 2); digester.parse(xmlfile); } catch (SAXParseException saxex) { logger.error( "Sax parsing error processing file " + xmlfile.getName()); throw new LogInputSourceException("Error during xml input source processing"); } catch(ParserConfigurationException pce){ logger.error("Xerces parser not properly configured "+pce.toString()); throw new LogInputSourceException("Error during xml input source processing"); } catch (IOException ioe) { logger.error("IO error processing file " + xmlfile.getName()); throw new LogInputSourceException("Error during xml input source processing"); } catch (SAXNotSupportedException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (SAXNotRecognizedException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (SAXException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } // Method called by Apache digester // Must be public public void setLogInputDir(String dirname){ // The XML file is constructed in a way that the directory name // is shared by log inputs. This method is called by digester after // the addLogInput method while (! LogInputsStack.empty()) { LogInput lgin=(LogInput)LogInputsStack.pop(); if ( dirname !=null ) { lgin.setDir(dirname); loginputs.add(lgin); } } } // Method called by Apache digester // Must be public public void addLogInput(String number,String type,String pattern) { // Create a stack of log inputs. The directory name is missing // so it can not be added to the loginputs array list now LogInput lgin = new LogInput(); LogPattern lgp=null; try { if (type !=null && type.equalsIgnoreCase("perl5")) { lgp=new LogPattern(pattern,LogPattern.PERL5TYPE); } else { lgp=new LogPattern(pattern); } } catch (MalformedLogPatternException e) { logger.error("Malformed pattern: "+pattern); return; } lgin.setHistnum(Integer.parseInt(number)); lgin.setPattern(lgp); this.LogInputsStack.push(lgin); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org