在 FOP 转换之前验证 XML
我想在对其运行 FOP 转换之前,根据 XML 架构验证 XMLReader 的 XML 输出。
我可以独立执行这两个步骤,但这意味着 XMLReader 被处理两次。我看不到如何使用验证器的输出并将其反馈到转换中。
我正在运行的代码如下。
感谢您提供的任何帮助
来源:
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);
I want to validate the XML output from my XMLReader against an XML Schema, before running a FOP transform on it.
I can do the two steps independently, but this means that the XMLReader is processed twice. I can't see how to use the output from the Validator and feed it back into the transform.
The code I am running is below.
Thanks for any help
the source:
Source src = new SAXSource(myXMLReader, myInputSource);
the validation:
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);
the transform:
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论