On Mon, 2006-03-20 at 13:38 -0500, Bill Burke wrote:
> Tell me something I don't already know.  I want validation if there is a 
> schema specified, no validation if there is not.
> 

And no default attributes, etc.

> Adrian Brock wrote:
> > The element declaration is required (from your error message)
> > http://www.w3.org/TR/xmlschema-1/#cvc-elt
> > 
> > and validation is required for minimal conformance:
> > http://www.w3.org/TR/xmlschema-1/#concepts-conformance
> > 
> > On Mon, 2006-03-20 at 13:20 -0500, 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;
> >>    }
> >>
> >>
> 
-- 
xxxxxxxxxxxxxxxxxxxxxxxx
Adrian Brock
Chief Scientist
JBoss Inc.
xxxxxxxxxxxxxxxxxxxxxxxx



-------------------------------------------------------
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