本文整理匯總了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();
}