I'm looking at how we do parsing and looking at XmlFileLoader.LocalErrorHandler.

It looks like errors are ignored if the schema wasn't resolved. Is this the way to do it?

Bill Burke wrote:
How do you set up xml parsing to not validate if there is no schema specified in the XML?

Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'persistence'. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
        at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)

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

HEM is doing the following code and throwing an error:

private static Document loadURL(URL configURL, EntityResolver resolver) throws Exception {
        InputStream is = configURL != null ? configURL.openStream() : null;
        if ( is == null ) {
throw new IOException( "Failed to obtain InputStream from url: " + configURL );
        }
        List errors = new ArrayList();
        DocumentBuilderFactory docBuilderFactory = null;
        docBuilderFactory = DocumentBuilderFactory.newInstance();
        docBuilderFactory.setValidating( true );
        docBuilderFactory.setNamespaceAware( true );
        try {
            //otherwise Xerces fails in validation
docBuilderFactory.setAttribute( "http://apache.org/xml/features/validation/schema";, true);
        }
        catch (IllegalArgumentException e) {
            docBuilderFactory.setValidating( false );
            docBuilderFactory.setNamespaceAware( false );
        }
        InputSource source = new InputSource( is );
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        docBuilder.setEntityResolver( resolver );
docBuilder.setErrorHandler( new ErrorLogger("XML InputStream", errors) );
        Document doc = docBuilder.parse( source );
      if ( errors.size() != 0 ) {
throw new PersistenceException( "invalid persistence.xml", (Throwable) errors.get( 0 ) );
        }
        return doc;
    }



--
Bill Burke
Chief Architect
JBoss Inc.


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-Development mailing list
JBoss-Development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to