XSD-Validation does not work under fuse-esb-3.4.0.5-unix, but under ...
misterbab Apr 29, 2010 1:11 PMHi
...fuse-esb-3.4.0.5-windows it's working.
I receive the following exception:
Validation: Error - File is NOT valid to Businesscase_Export_v6_9.xsd
Exception: java.lang.Exception: java.lang.Exception: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'businesscases'
The same xml valiation works in windows fuse esb and in the same version for unix i get an exception. Why?
I run fuse esb under suse linux enterprise 11, java Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04), Java HotSpot(TM) 64-Bit Server VM.
...The xml document is valid and the xsd file should be found, because the name is printed in the exception snipped.
Follwing my custom code. The inputstream is a xml document (attached: XMLinputStream.xml) and it is validated against the schema (attached: Businesscase_Export_v6_9.xsd).
Custom code:
================================
238 public synchronized static void validateXML(InputStream xmlInputStream, String xsdPathesProperty) throws Exception {[239|https://www2.hosted-projects.com/trac/renehelbig/ESB/browser/sources/branch/soliver-R2/Sources/sportscheck_utils/src/main/java/de/mmsdresden/sportscheck/utils/XMLUtils.java#L239] // get path from property //
240 PropertyLoaderImpl props = (PropertyLoaderImpl) new PathPropertyFactory().getImplementation();
241 String path = props.getValueAbsolute(xsdPathesProperty);
242 // check for an xsd at given path //
243 File xsd = IOUtils.CheckForXSD(new File(path));
244 if (xsd != null) {
245 // validate the InputStream //
246 LOGGER.info("Validation: Starting Validation with " + xsd.getName());
247 try {
248 DocumentBuilder parser;
249 // DOM tree //
250 parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
251 org.w3c.dom.Document document = parser.parse(xmlInputStream);
252 // remove in xml file given schema declaration
253 document.getDocumentElement().removeAttribute("xsi:noNamespaceSchemaLocation");
254 // SchemaFactory for WXS schemas //
255 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
256 // load the WXS schema //
257 Source schemaFile = new StreamSource(xsd);
258 Schema schema = factory.newSchema(schemaFile);
259 // validate //
260 Validator validator = schema.newValidator();
261 validator.validate(new DOMSource(document));
262 } catch (Exception e) {
263 LOGGER.info("Validation: Error - File is NOT valid to " + xsd.getName());
264 throw new Exception(e);
265 }
266 LOGGER.info("Validation: Done - File is valid to " + xsd.getName())
268 LOGGER.info("Validation: Skipping - No XSD found at given Path");
269 }
270 }
Thanks for helping,
Andreas.
Edited by: misterbab on Apr 29, 2010 5:08 PM