I have written a program using Xerces-J 2.9.1 JAXP 1.3 DOM APIs to validate XML documents with the XML Schema. The program is below (I have omitted imports):
public class SchmValidateDOM implements ErrorHandler { public static void main(String[] args) { SchmValidateDOM sv = new SchmValidateDOM(); sv.parseFile(args[0]); } private void parseFile(String filename) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); docBuilder.setErrorHandler(this); Document document = docBuilder.parse(new File(filename)); NodeList nl = document.getElementsByTagName("QUANTITY"); for (int i = 0; i < nl.getLength(); i++) { System.out.println(nl.item(i).getFirstChild().getNodeValue()); } } catch(ParserConfigurationException pce) { pce.printStackTrace(); } catch(SAXException se) { se.printStackTrace(); } catch(IOException ioe) { ioe.printStackTrace(); } } public void error(SAXParseException exception) throws SAXException { System.out.println("Line: "+exception.getLineNumber()+", Column: "+exception.getColumnNumber()+", Message: "+exception.getMessage()); } public void fatalError(SAXParseException exception) throws SAXException { System.out.println("Line: "+exception.getLineNumber()+", Column: "+exception.getColumnNumber()+", Message: "+exception.getMessage()); } public void warning(SAXParseException exception) throws SAXException { System.out.println("Line: "+exception.getLineNumber()+", Column: "+exception.getColumnNumber()+", Message: "+exception.getMessage()); } } I have overridden the ErrorHandler to have my custom behaviour. This program works fine, and for an example XML document, it produces the following output: Line: 24, Column: 9, Message: cvc-complex-type.2.4.a: Invalid content was found starting with element 'ISBN'. One of '{QUANTITY}' is expected. 187 85 129 129 129 You could see spurious integers appearing in the output at the end. Can this be classified as a low priority bug ? Should I put this in Jira ? Using the SAXParser, this problem doesn't come. -- Regards, Mukul Gandhi --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]