如何使用 Java 根据 wml.xsd 验证 Word 2007 文件?

发布于 2024-08-11 23:04:57 字数 307 浏览 2 评论 0原文

我想根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿萝 2024-08-18 23:04:57

根据架构,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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文