예제 #1
0
 /**
  * Validates an xml document with respect to schemaLocation hints using supplied error handler.
  *
  * @param xml
  * @param eh
  * @return
  * @throws Exception
  */
 public static Element validateInfo(Element xml, ErrorHandler eh) throws Exception {
   Schema schema = factory().newSchema();
   validateRealGuts(schema, xml, eh);
   if (eh.errors()) {
     return eh.getXPaths();
   } else {
     return null;
   }
 }
예제 #2
0
 /**
  * Validates an XML document using the hints in the schemaLocation attribute.
  *
  * @param xml
  * @throws Exception
  */
 public static synchronized void validate(Element xml) throws Exception {
   Schema schema = factory().newSchema();
   ErrorHandler eh = new ErrorHandler();
   validateRealGuts(schema, xml, eh);
   if (eh.errors()) {
     Element xsdXPaths = eh.getXPaths();
     throw new XSDValidationErrorEx(
         "XSD Validation error(s):\n" + getString(xsdXPaths), xsdXPaths);
   }
 }
예제 #3
0
 /**
  * Called by validation methods that supply an xml schema described by .xsd file path.
  *
  * @param schemaPath
  * @param xml
  * @param eh
  * @throws Exception
  */
 private static void validateGuts(String schemaPath, Element xml, ErrorHandler eh)
     throws Exception {
   StreamSource schemaFile = new StreamSource(new File(schemaPath));
   Schema schema = factory().newSchema(schemaFile);
   validateRealGuts(schema, xml, eh);
 }