public static <T>T parse(InputStream xml,String xmlPath,String[] xsds,String pkg,Class<T> resultClass) throws XmlParsingException {
  try {
    JAXBContext jaxbContext=JAXBContext.newInstance(pkg);
    Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
    UnmarshallerHandler unmarshallerHandler=unmarshaller.getUnmarshallerHandler();
    XmlParsingHandler contentErrorHandler=new XmlParsingHandlerWrapper(unmarshallerHandler,xmlPath);
    doParse(xml,xsds,contentErrorHandler);
    Object result=JAXBIntrospector.getValue(unmarshallerHandler.getResult());
    if (!resultClass.isInstance(result)) {
      throw new RuntimeException(String.format("A root element in '%s' must be an instance of %s type.",xmlPath,resultClass.getSimpleName()));
    }
    return (T)result;
  }
 catch (  JAXBException e) {
    throw new RuntimeException(e);
  }
}

public static < T > T parse ( InputStream xml , String xmlPath , String [ ] xsds , String pkg , Class < T > resultClass ) throws XmlParsingException { try { JAXBContext jaxbContext = JAXBContext . newInstance ( pkg ) ; Unmarshaller unmarshaller = jaxbContext . createUnmarshaller ( ) ; UnmarshallerHandler unmarshallerHandler = unmarshaller . getUnmarshallerHandler ( ) ; XmlParsingHandler contentErrorHandler = new XmlParsingHandlerWrapper ( unmarshallerHandler , xmlPath ) ; doParse ( xml , xsds , contentErrorHandler ) ; Object result = JAXBIntrospector . getValue ( unmarshallerHandler . getResult ( ) ) ; if ( ! resultClass . isInstance ( result ) ) { throw new RuntimeException ( String . format ( "A root element in '%s' must be an instance of %s type." , xmlPath , resultClass . getSimpleName ( ) ) ) ; } return ( T ) result ; } catch ( JAXBException e ) { throw new RuntimeException ( e ) ; } }
parses the given xml to a java model ( jaxb unmarshalling ) . performs xsd validation .
