本文整理匯總了Java中org.dom4j.io.SAXReader.setValidation方法的典型用法代碼示例。如果您正苦於以下問題:Java SAXReader.setValidation方法的具體用法?Java SAXReader.setValidation怎麽用?Java SAXReader.setValidation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dom4j.io.SAXReader
的用法示例。
在下文中一共展示了SAXReader.setValidation方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setValidationFor
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
private void setValidationFor(SAXReader saxReader, String xsd) {
try {
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
// saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
if ( "orm_2_1.xsd".equals( xsd ) ) {
saxReader.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation",
"http://xmlns.jcp.org/xml/ns/persistence/orm " + xsd
);
}
else {
saxReader.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation",
"http://java.sun.com/xml/ns/persistence/orm " + xsd
);
}
}
catch ( SAXException e ) {
saxReader.setValidation( false );
}
}
示例2: legacyReadMappingDocument
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
private XmlDocument legacyReadMappingDocument(EntityResolver entityResolver, InputSource source, Origin origin) {
// IMPL NOTE : this is the legacy logic as pulled from the old AnnotationConfiguration code
Exception failure;
ErrorLogger errorHandler = new ErrorLogger();
SAXReader saxReader = new SAXReader();
saxReader.setEntityResolver( entityResolver );
saxReader.setErrorHandler( errorHandler );
saxReader.setMergeAdjacentText( true );
saxReader.setValidation( true );
Document document = null;
try {
// first try with orm 2.1 xsd validation
setValidationFor( saxReader, "orm_2_1.xsd" );
document = saxReader.read( source );
if ( errorHandler.hasErrors() ) {
throw errorHandler.getErrors().get( 0 );
}
return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
}
catch ( Exception e ) {
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Problem parsing XML using orm 2.1 xsd, trying 2.0 xsd : %s", e.getMessage() );
}
failure = e;
errorHandler.reset();
if ( document != null ) {
// next try with orm 2.0 xsd validation
try {
setValidationFor( saxReader, "orm_2_0.xsd" );
document = saxReader.read( new StringReader( document.asXML() ) );
if ( errorHandler.hasErrors() ) {
errorHandler.logErrors();
throw errorHandler.getErrors().get( 0 );
}
return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
}
catch ( Exception e2 ) {
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Problem parsing XML using orm 2.0 xsd, trying 1.0 xsd : %s", e2.getMessage() );
}
errorHandler.reset();
if ( document != null ) {
// next try with orm 1.0 xsd validation
try {
setValidationFor( saxReader, "orm_1_0.xsd" );
document = saxReader.read( new StringReader( document.asXML() ) );
if ( errorHandler.hasErrors() ) {
errorHandler.logErrors();
throw errorHandler.getErrors().get( 0 );
}
return new XmlDocumentImpl( document, origin.getType(), origin.getName() );
}
catch ( Exception e3 ) {
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Problem parsing XML using orm 1.0 xsd : %s", e3.getMessage() );
}
}
}
}
}
}
throw new InvalidMappingException( "Unable to read XML", origin.getType(), origin.getName(), failure );
}