Re: [JBoss-dev] optional schema validation
yeah, this seems to work, but does anybody know if there is a better way? Bill Burke wrote: 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
Re: [JBoss-dev] optional schema validation
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; > >>} > >> > >> > -- Adrian Brock Chief Scientist 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
Re: [JBoss-dev] optional schema validation
Tell me something I don't already know. I want validation if there is a schema specified, no validation if there is not. 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; } -- 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
Re: [JBoss-dev] optional schema validation
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; > } > > -- Adrian Brock Chief Scientist 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
Re: [JBoss-dev] optional schema validation
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
[JBoss-dev] optional schema validation
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