我正在尝试创建一个解析器来查找跟踪的更改和 Word.docx
文件的作者...
我找到了,document.xml
但是标签太多了!所有这些标签所代表的含义是否有词汇表?
如果可能的话,我想避免强行通过这个。
您可以在Stack Overflow docx 标签 wiki 本身中开始收集有关它的信息。
.docx
文件(以及其他新的 MS Office 文件,如.xlsx
)使用 OOXML 格式
尤其是 :
Microsoft Office Open XML WordProcessingML 主要在 ECMA 376 和 ISO 29500 中标准化。
您可以在此处获取相关的 ECMA 标准规范:http: //www.ecma-international.org/news/TC45_current_work/TC45_available_docs.htm
您可能正在寻找的特定文档可能是Open Office XML,第 4 部分:标记语言参考
但当然......这是巨大的(5219页!)
我强烈建议您确定您想要的功能,并查看现有的开源库,这些库已经完成了您想做的一些工作。
“Office Open XML”格式及其 XML 词汇表在http://www.ecma-international.org/publications/standards/Ecma-376.htm中有详细描述。
为了给您一个想法,下面的 XSLT应该只提取有效的结果文本,而不需要对 wordprocessingML 文档进行跟踪删除,就像存储word/document.xml
在 .docx 文件(ZIP 存档)中一样。
<!-- Match and output text spans except when
appearing in w:delText child content -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<xsl:output method="text"/>
<xsl:template match="w:t">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="w:delText"/>
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
为了让您的应用程序改为提取更改,您还必须处理w:ins
元素。
您可以使用我的 docx4j webapp,特别是http://webapp.docx4java.org/OnlineDemo/PartsList.html
有了它,您可以单击一个标签,它将带您到规范中的相应定义。
"w:ins" denotes what was inserted when trackedchanges are enabled.
"w:del" denotes what was deleted when trackedchanges are enabled.
"w:commentRangeStart" denotes the start of a comment
"w:commentRangeEnd" denotes the end of the comment.
All text are found inside
"w:t" tags.