本文整理汇总了Java中javax.xml.validation.ValidatorHandler.setFeature方法的典型用法代码示例。如果您正苦于以下问题:Java ValidatorHandler.setFeature方法的具体用法?Java ValidatorHandler.setFeature怎么用?Java ValidatorHandler.setFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.validation.ValidatorHandler
的用法示例。
在下文中一共展示了ValidatorHandler.setFeature方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseAndValidate
import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
/**
* Parse and Validate an XML represented by the input stream against provided XSD and reports validation issues.
*
* @param input XML to parse and validate
* @param vHandler Validator handler
* @throws IOException If a IO error occurs during XML parsing.
* @throws XmlParseException If a SAX error occurs during XML parsing.
*/
protected void parseAndValidate(InputStream input, ValidatorHandler vHandler) throws XmlParseException, IOException {
vHandler.setErrorHandler(this);
InputSource is = new InputSource(new InputStreamReader(input, "UTF-8"));
is.setEncoding("UTF-8");
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(vHandler);
parser.setErrorHandler(this);
vHandler.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
// Commented out the following line, as Java 1.6.0_45 throws an exception on this.
//parser.setFeature("http://apache.org/xml/features/validation/id-idref-checking", false);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
parser.setFeature("http://xml.org/sax/features/external-general-entities", false);
parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
parser.parse(is);
} catch (SAXException e) {
throw new XmlParseException(e.getMessage(), e);
}
}
示例2: parseAndValidate
import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
private void parseAndValidate(InputStream input, Schema schema) throws XmlParseException, IOException {
ValidatorHandler vHandler = schema.newValidatorHandler();
vHandler.setContentHandler(this);
vHandler.setErrorHandler(this);
InputSource is = new InputSource(new InputStreamReader(input, "UTF-8"));
is.setEncoding("UTF-8");
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(vHandler);
parser.setErrorHandler(this);
vHandler.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
parser.setFeature("http://apache.org/xml/features/validation/id-idref-checking", false);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
parser.setFeature("http://xml.org/sax/features/external-general-entities", false);
parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
parser.parse(is);
} catch (SAXException e) {
throw new XmlParseException(e.getMessage(), e);
}
}
示例3: test1
import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test
public void test1() throws Exception {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
ValidatorHandler validatorHandler = schemaFactory.newSchema().newValidatorHandler();
validatorHandler.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
validatorHandler.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
}
示例4: test
import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
ValidatorHandler validatorHandler = schemaFactory.newSchema().newValidatorHandler();
try {
validatorHandler.setFeature(null, false);
Assert.fail("should report an error");
} catch (NullPointerException e) {
; // expected
}
}
示例5: testFeature
import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
public void testFeature() throws SAXNotRecognizedException, SAXNotSupportedException {
ValidatorHandler validatorHandler = getValidatorHandler();
assertFalse(validatorHandler.getFeature(FEATURE_NAME), "The feature should be false by default.");
validatorHandler.setFeature(FEATURE_NAME, true);
assertTrue(validatorHandler.getFeature(FEATURE_NAME), "The feature should be false by default.");
}
示例6: testSetNullFeature
import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void testSetNullFeature() throws SAXNotRecognizedException, SAXNotSupportedException {
ValidatorHandler validatorHandler = getValidatorHandler();
assertNotNull(validatorHandler);
validatorHandler.setFeature(null, true);
}