本文整理汇总了Java中javax.xml.validation.Schema.newValidatorHandler方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.newValidatorHandler方法的具体用法?Java Schema.newValidatorHandler怎么用?Java Schema.newValidatorHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.validation.Schema
的用法示例。
在下文中一共展示了Schema.newValidatorHandler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import javax.xml.validation.Schema; //导入方法依赖的package包/类
@Test
public void test() throws SAXException, ParserConfigurationException, IOException {
SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(XML_DIR + "shiporder11.xsd"));
validatorHandler = schema.newValidatorHandler();
MyDefaultHandler myDefaultHandler = new MyDefaultHandler();
validatorHandler.setContentHandler(myDefaultHandler);
InputSource is = new InputSource(filenameToURL(XML_DIR + "shiporder11.xml"));
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
XMLReader xmlReader = parserFactory.newSAXParser().getXMLReader();
xmlReader.setContentHandler(validatorHandler);
xmlReader.parse(is);
}
示例2: ValidatingUnmarshaller
import javax.xml.validation.Schema; //导入方法依赖的package包/类
/**
* Creates a new instance of ValidatingUnmarshaller.
*/
public ValidatingUnmarshaller( Schema schema, XmlVisitor next ) {
this.validator = schema.newValidatorHandler();
this.next = next;
this.predictor = next.getPredictor();
// if the user bothers to use a validator, make validation errors fatal
// so that it will abort unmarshalling.
validator.setErrorHandler(new FatalAdapter(getContext()));
}
示例3: createValidatorHandler
import javax.xml.validation.Schema; //导入方法依赖的package包/类
private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
StringReader reader = new StringReader(xsd);
StreamSource xsdSource = new StreamSource(reader);
Schema schema = schemaFactory.newSchema(xsdSource);
return schema.newValidatorHandler();
}
示例4: createValidatorHandler
import javax.xml.validation.Schema; //导入方法依赖的package包/类
private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(xsd.getBytes()));
StreamSource xsdSource = new StreamSource(reader);
Schema schema = schemaFactory.newSchema(xsdSource);
return schema.newValidatorHandler();
}
示例5: setUp
import javax.xml.validation.Schema; //导入方法依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(XSD.getBytes()));
StreamSource xsdSource = new StreamSource(reader);
Schema schema = schemaFactory.newSchema(xsdSource);
this.validatorHandler = schema.newValidatorHandler();
this.validator = schema.newValidator();
}