/** Parses profile string into DOM document */ private Document parseIntoDOM(String profileString) throws ProfileException { try { Document doc = XMLUtils.parse(profileString, true); if (alwaysValidate) XMLUtils.validate(doc, PROFILE_XSD, errorHandler); return doc; } catch (Exception e) { throw new ProfileException("Exception parsing message profile: " + e.getMessage(), e); } }
/** Parses profile string into DOM document */ private Document parseIntoDOM(String profileString) throws ProfileException { try { Document doc = XMLUtils.parse(profileString, true); if (alwaysValidate) XMLUtils.validate(doc, PROFILE_XSD, errorHandler); return doc; } catch (Exception e) { throw new ProfileException("Exception parsing message profile: " + e.getMessage(), e); } }
/** * Test/validate a given xml document against a hl7 v2.xml schema. * <p> * Before the schema is applied, the namespace is verified because otherwise schema validation * fails anyway. * <p> * If a schema file is specified in the xml message and the file can be located on the disk this * one is used. If no schema has been specified, or the file can't be located, the locations * property is used. * * @param msg the xml message (as string) to be validated. * @return ValidationException[] an array of validation exceptions, which is zero-sized when no * validation errors occured. */ public ValidationException[] apply(String msg) { List<ValidationException> validationErrors = new ArrayList<ValidationException>(); try { // parse the incoming string into a dom document - no schema validation yet Document doc = XMLUtils.parse(msg); if (hasCorrectNamespace(doc, validationErrors)) { XMLUtils.validate(doc, getSchemaLocation(doc), new ErrorHandler(validationErrors)); } } catch (Exception e) { log.error("Unable to validate message: {}", e.getMessage(), e); validationErrors.add(new ValidationException("Unable to validate message " + e.getMessage(), e)); } return validationErrors.toArray(new ValidationException[validationErrors.size()]); }
/** * Test/validate a given xml document against a hl7 v2.xml schema. * <p> * Before the schema is applied, the namespace is verified because otherwise schema validation * fails anyway. * <p> * If a schema file is specified in the xml message and the file can be located on the disk this * one is used. If no schema has been specified, or the file can't be located, the locations * property is used. * * @param msg the xml message (as string) to be validated. * @return ValidationException[] an array of validation exceptions, which is zero-sized when no * validation errors occured. */ public ValidationException[] apply(String msg) { List<ValidationException> validationErrors = new ArrayList<ValidationException>(); try { // parse the incoming string into a dom document - no schema validation yet Document doc = XMLUtils.parse(msg); if (hasCorrectNamespace(doc, validationErrors)) { XMLUtils.validate(doc, getSchemaLocation(doc), new ErrorHandler(validationErrors)); } } catch (Exception e) { log.error("Unable to validate message: {}", e.getMessage(), e); validationErrors.add(new ValidationException("Unable to validate message " + e.getMessage(), e)); } return validationErrors.toArray(new ValidationException[validationErrors.size()]); }