LoggingErrorHandler errorHandler = new LoggingErrorHandler(); validator.setErrorHandler(errorHandler); validator.validate(invalidXmlSource); if (!errorHandler.isValid()) { //... }
/** * Builds a schema from the given schema sources. * * @param lang schema language, must not be null * @param schemaSources schema sources, must not be null * * @return the constructed schema * * @throws SAXException thrown if there is a problem converting the schema sources in to a schema */ protected static Schema buildSchema(SchemaLanguage lang, Source[] schemaSources) throws SAXException { if(lang == null){ throw new IllegalArgumentException("Schema language may not be null"); } if(schemaSources == null){ throw new IllegalArgumentException("Schema sources may not be null"); } SchemaFactory schemaFactory; if (lang == SchemaLanguage.XML) { schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); } else { schemaFactory = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI); } schemaFactory.setErrorHandler(new LoggingErrorHandler(LoggerFactory.getLogger(SchemaBuilder.class))); return schemaFactory.newSchema(schemaSources); }
/** * Builds a schema from the given schema sources. * * @param lang schema language, must not be null * @param schemaSources schema sources, must not be null * * @return the constructed schema * * @throws SAXException thrown if there is a problem converting the schema sources in to a schema */ protected static Schema buildSchema(SchemaLanguage lang, Source[] schemaSources) throws SAXException { if(lang == null){ throw new IllegalArgumentException("Schema language may not be null"); } if(schemaSources == null){ throw new IllegalArgumentException("Schema sources may not be null"); } SchemaFactory schemaFactory; if (lang == SchemaLanguage.XML) { schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); } else { schemaFactory = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI); } schemaFactory.setErrorHandler(new LoggingErrorHandler(LoggerFactory.getLogger(SchemaBuilder.class))); return schemaFactory.newSchema(schemaSources); }
/** Constructor. */ public StaticBasicParserPool() { initialized = false; maxPoolSize = 5; builderPool = new Stack<SoftReference<DocumentBuilder>>(); builderAttributes = new LazyMap<String, Object>(); coalescing = true; expandEntityReferences = false; builderFeatures = buildDefaultFeatures(); ignoreComments = true; ignoreElementContentWhitespace = true; namespaceAware = true; schema = null; dtdValidating = false; xincludeAware = false; errorHandler = new LoggingErrorHandler(log); }
Validator validator = SchemaFactory .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new StreamSource(new StringReader(xsd))) .newValidator(); LoggingErrorHandler errorHandler = new LoggingErrorHandler(); validator.setErrorHandler(errorHandler); validator.validate(new StreamSource(new StringReader(xml))); return errorHandler.isValid();
/** Constructor. */ public StaticBasicParserPool() { initialized = false; maxPoolSize = 5; builderPool = new Stack<SoftReference<DocumentBuilder>>(); builderAttributes = new LazyMap<String, Object>(); coalescing = true; expandEntityReferences = false; builderFeatures = buildDefaultFeatures(); ignoreComments = true; ignoreElementContentWhitespace = true; namespaceAware = true; schema = null; dtdValidating = false; xincludeAware = false; errorHandler = new LoggingErrorHandler(log); }
schemaFactory.setErrorHandler(new LoggingErrorHandler(LoggerFactory.getLogger(clazz))); return schemaFactory.newSchema(schemaSources.toArray(new StreamSource[0]));
ErrorHandler mySchemaErrorHandler = new LoggingErrorHandler(); validator.setErrorHandler(mySchemaErrorHandler); DOMSource domSource = new DOMSource(domResult.getNode());
/** Constructor. */ public BasicParserPool() { maxPoolSize = 5; builderPool = new Stack<SoftReference<DocumentBuilder>>(); builderAttributes = new LazyMap<String, Object>(); coalescing = true; expandEntityReferences = false; builderFeatures = buildDefaultFeatures(); ignoreComments = true; ignoreElementContentWhitespace = true; namespaceAware = true; schema = null; dtdValidating = false; xincludeAware = false; errorHandler = new LoggingErrorHandler(log); try { dirtyBuilderConfiguration = true; initializePool(); } catch (XMLParserException e) { // default settings, no parsing exception } }
/** Constructor. */ public BasicParserPool() { maxPoolSize = 5; builderPool = new Stack<SoftReference<DocumentBuilder>>(); builderAttributes = new LazyMap<String, Object>(); coalescing = true; expandEntityReferences = false; builderFeatures = buildDefaultFeatures(); ignoreComments = true; ignoreElementContentWhitespace = true; namespaceAware = true; schema = null; dtdValidating = false; xincludeAware = false; errorHandler = new LoggingErrorHandler(log); try { dirtyBuilderConfiguration = true; initializePool(); } catch (XMLParserException e) { // default settings, no parsing exception } }
public void test() { ErrorHandler handler = new LoggingErrorHandler();