如何使用 Java 根据 wml.xsd 验证 Word 2007 文件?
我想根据 wml.xsd 中定义的架构验证给定的 Word 2007 XML 文件。 用Java怎么能做到呢? 使用以下行加载架构不是问题。但似乎我必须调整验证过程,因为即使在有效的输入文件上我也会收到错误消息(我可以在 Word 2007 中打开并查看输入文件而不会出现警告)
Schema schema = schemaFactory.newSchema(source); // <-- complains on valid input files
Validator validator = schema.newValidator();
I would like to validate a given Word 2007 XML file against the Schema defined in wml.xsd.
How could it be done in Java?
Loading the Schema with the following line is not a problem. But it seems that I have to tweak the validation process becaus I get error messages even on valid input files (I could open and view the input file in Word 2007 without warnings)
Schema schema = schemaFactory.newSchema(source); // <-- complains on valid input files
Validator validator = schema.newValidator();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据架构,Word 文件有可能在 Word 中可用,但也可能无效。可能是,Word 文件使用了不同版本的架构,也可能是 MS Word 对无效文件放宽了一些。
为了进行检查,我将文件和架构加载到 Eclipse 项目中 - Eclipse 需要配备 Web 标准工具插件 - 并使用 xml 编辑器打开 word xml 文件。编辑器将显示验证错误(您可能需要手动执行验证操作)
There is a chance, that the word file is usable in word as well as invalid according to the schema. Could be, that the word file uses a different version of the schema, could be that MS word relaxes a bit on invalid files.
To check, I'd load file and schema into an eclipse project - eclipse need to be equipped with the web standard tools plugin - and open the word xml file with the xml editor. The editor will show validation errors (you may have to execute the validate action manually)