XML/XSD validation for a Word doc

送分小仙女□ 提交于 2020-01-05 04:58:35

问题


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.

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)

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


回答1:


Preface: Ken White is right when he comments that you should improve your existing question rather than re-ask it without substantial improvement. I'll place this answer here since this version of your question is slightly better than the other; please delete the other.

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.

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.

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

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).

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.



来源:https://stackoverflow.com/questions/37801066/xml-xsd-validation-for-a-word-doc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!