[prev in list] [next in list] [prev in thread] [next in thread]
List: xerces-j-dev
Subject: Re: How to configure xerces_2_9_0 with java 6 and multiple error response ?
From: Michael Glavassevich <mrglavas () ca ! ibm ! com>
Date: 2008-01-24 19:17:57
Message-ID: OF12E98820.36890167-ON852573DA.0069494D-852573DA.006A05E3 () ca ! ibm ! com
[Download RAW message or body]
"Jing Yang" <jyang@jbmanagement.com> wrote on 01/24/2008 01:51:28 PM:
> Two questions:
> 1) How to use xerces_2_9_0 rather than the default schema
> parser of java 6 ?
Putting Xerces' jars (xml-apis.jar and xercesImpl.jar) on the classpath
should work. Failing that you should use the Endorsed Standards Override
Mechanism. More info here: http://java.sun.com/j2se/1.5.0
/docs/guide/standards/.
> 2) Try to use jaxp 1.3 APIs to perform schema validation, but
> same error was reported twice. How to fix it?
They might look the same but they're violations of different schema
constraints. Xerces reports an error for each.
> The error was
> Line:3 Column:77 cvc-datatype-valid.1.2.1: '123a' is not a valid
> value for 'integer'.
> Line:3 Column:77 cvc-type.3.1.3: The value '123a' of element
> 'number' is not valid.
>
> The codes are listed as below:
> SchemaFactory factory = SchemaFactory.newInstance("http:
> //www.w3.org/2001/XMLSchema");
> File schemaLocation = new File(schemaPath);
> try{
> Schema schema = factory.newSchema(schemaLocation);
> Validator validator = schema.newValidator();
> ErrorHandler lenient = new ForgivingErrorHandler();
> validator.setErrorHandler(lenient);
> Source source = new StreamSource(input);
>
> validator.validate(source);
>
> }
> catch(Exception e){
> System.out.println("ex "+e);
> }
>
> public class ForgivingErrorHandler implements ErrorHandler {
> static Logger logger = Logger.getLogger(ForgivingErrorHandler.class
> .getName());
> private ArrayList<String> errors;
> public void warning(SAXParseException ex) {
> String msg=getFormattedMsg(ex);
> putError(msg);
> }
>
> public void error(SAXParseException ex) {
> String msg=getFormattedMsg(ex);
> putError(msg);
> System.out.println(msg);
> }
> public void fatalError(SAXParseException ex) throws SAXException{
> throw ex;
> }
> private String getFormattedMsg(SAXParseException ex){
> StringBuffer strBuff=new StringBuffer();
> strBuff.append("Line:");
> strBuff.append(ex.getLineNumber());
> strBuff.append(" Column:");
> strBuff.append(ex.getColumnNumber());
> strBuff.append(" ");
> strBuff.append(ex.getMessage());
> return strBuff.toString();
> }
> private void putError(String msg){
> if(errors ==null){
> errors=new ArrayList<String>();
> }
> errors.add(msg);
> }
> public ArrayList<String> getErrors(){
> return errors;
> }
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic