Word 文档的 XML/XSD 验证 [英] XML/XSD validation for a Word doc

查看:37
本文介绍了Word 文档的 XML/XSD 验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个会不断更新的文档,它由文本和表格组成.这些表格有两行,一排是数字范围,第二排是一个数字.

I have a document that will constantly be updated and consists of text and tables. The tables have two rows, one which ranges of numbers and the second with a single number.

我想检查第 2 行中的数字是否在第 1 行给出的范围内.我想使用 XML 和 XSD 来执行此操作.我最初的想法是从单词 doc 创建一个 XSD,然后从单词 doc 创建一个 XML(将文件另存为 .xml),然后通过 vaidator 运行这两个文件.但是,我在编写 XSD 时遇到了麻烦.许多在线资源都说要从 XML 生成 XSD 并使用该 XSD 来验证 XML.但问题是如果我这样做,我没有看到 XSD 中指定的任何范围.它看起来像文档格式规范.有谁知道是否有任何工具可以执行此任务,或者是否需要手动生成 XSD.我的最终目标是自动化这个过程,这样给定一个文档,我有一个 XSD 并且可以生成一个 XML,然后我可以更改 XML 中的值,并根据 XSD 查看它是否在有效范围内(应该检查范围).我真的被困在如何自动化这个过程(或者即使有一种方法可以自动化它)

I would like to check if the number in row 2 is within the range given in row 1. I would like to do this using XMLs and XSDs. My original thought was to create an XSD from the word doc, then an XML from the word doc (save the file as a .xml) and then run both files through a vaidator. However, I am having trouble writing the XSD. A lot of sources online say to generate an XSD from and XML and use that XSD to validate the XML. But the problem is if I do this, I'm not seeing any ranges specified in the XSD. It just looks like doc formatting specifications. Does anyone know if there any tools to do this task or is this something where I need to generate the XSD manually. My ultimate goal is to automate the process such that given a doc, I have an XSD and can generate an XML, then I can just change values in the XML and see if it is in a valid range according to the XSD(which should check ranges). I am really stuck on how I can automate this process (or even if there is a way to automate it)

这实际上是如何对架构中的范围进行限制 - http://www.w3schools.com/xml/schema_facets.asp

This is actually how one can do restrictions with ranges in schema - http://www.w3schools.com/xml/schema_facets.asp

推荐答案

自 Word 2007 起的 Microsoft Word 文档以符合 Office Open XML (OOXML) 标准.首先阅读此 Office Open XML 概述.了解了这一点,您就可以构建一些合理的搜索来查找 OOXML 教程和代码示例.了解这不是一个简单的 XML 项目.

Microsoft Word documents since Word 2007 are saved in a DOCX format that follows the Office Open XML (OOXML) standard. Start by reading this Office Open XML Overview. Knowing this, you'll then be able to construct some reasonable searches to find OOXML tutorials and code samples. Understand that this is not an easy first project in XML.

我想检查第 2 行的数字是否在给定的范围内在第 1 行.我想使用 XML 和 XSD 来做到这一点.

I would like to check if the number in row 2 is within the range given in row 1. I would like to do this using XMLs and XSDs.

XSD 在这里不合适.XPath 更适合以这种方式检索和检查值.

XSDs are not appropriate here. XPath would be better suited for retrieving and checking values in this manner.

我的最终目标是使流程自动化,以便给定文档,我有一个 XSD 并可以生成一个 XML,然后我可以更改值XML并根据XSD查看它是否在有效范围内(其中应该检查范围).

My ultimate goal is to automate the process such that given a doc, I have an XSD and can generate an XML, then I can just change values in the XML and see if it is in a valid range according to the XSD(which should check ranges).

再说一次,虽然有用于 OOXML(DOCX 背后的 XML)的 XSD,但它们支持对您的项目来说不必要的大量行李.转而研究通过使用您选择的语言的 XPath 调用对您寻求的数据进行简化的访问.您必须了解数据模型,因此请务必先阅读上面提到的 OOXML 参考资料.

Again, although there are XSDs for OOXML (the XML behind DOCX), they support extreme amounts of baggage unnecessary to your project. Look instead into streamlined access to the data you seek via XPath calls from the language of your choice. You'll have to understand the data model, so be sure to read the OOXML references mentioned above first.

这篇关于Word 文档的 XML/XSD 验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆