我希望在对XML Schema进行FOP转换之前,根据XML Schema验证XMLReader的XML输出。
我可以独立完成这两个步骤,但这意味着XMLReader会被处理两次。我无法看到如何使用Validator的输出并将其反馈回变换。
我正在运行的代码如下。
感谢您的帮助
来源:
Source src = new SAXSource(myXMLReader, myInputSource);
验证:
URL schemaUrl = this.getClass().getResource("/myschema.xsd");
String schemaLang = "http://www.w3.org/2001/XMLSchema";
SchemaFactory jaxp = SchemaFactory.newInstance(schemaLang);
Schema schema = jaxp.newSchema(schemaUrl);
Validator validator = schema.newValidator();
validator.validate(src);
变换:
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(this.getClass().getResourceAsStream("/MyTemplate.xslt")));
Result fopResult = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, fopResult);