且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

XML关系转换算法

更新时间:2023-11-24 09:05:04

有关转换以及这种情况下的关系转换的主要信息源可以在ECMA的" Office Open XML文件格式—开放包装约定"中找到. "文件.链接

The main source of information on transforms, and relationship transforms in this case, can be found in ECMA's "Office Open XML File Formats — Open Packaging Conventions" paper. Link here.

重要部分是13.2.4.24.

The section of importance is 13.2.4.24.

Relationship Transform应该创建.rels文件的副本,在这种情况下为"/_rels/.rels",并删除所有与 SourceId 不匹配的 Relationship 节点. >.该文件是最终经过哈希处理并创建摘要的文件.

Relationship Transform should create a copy of the .rels file, in this case "/_rels/.rels" and remove all Relationship nodes that don't match with SourceId. This file is what is eventually hashed and creates the digest.

包实现者应删除所有没有 Id值的Relationship元素 匹配任何SourceId值或匹配任何SourceType值的Type值, 在转换定义中指定的SourceId和SourceType值.

The package implementer shall remove all Relationship elements that do not have either an Id value that matches any SourceId value or a Type value that matches any SourceType value, among the SourceId and SourceType values specified in the transform definition.

在第3步准备规范化"中也指出:

Under step 3, "Prepare for canonicalization" it also states:

包实施者应添加一个 TargetMode 属性及其默认值(如果此可选) 关系元素中缺少属性

The package implementer shall add a TargetMode attribute with its default value, if this optional attribute is missing from the Relationship element

因为我们要在同一包中的文件之间创建关系,所以我们将其值为"内部".您需要先添加此属性,然后再对其进行哈希处理.

Because we are creating a relationship between files in the same package, we have the value of "Internal". You need to add this attribute before you hash it.

因此在转换和c14n之后,您应该具有:

So after the transform and c14n, you should have:

<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Target="word/document.xml" TargetMode="Internal" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"></Relationship></Relationships>

注意::如果您使用的是Unix系统,请注意换行符,OPC使用CRLF而不是LF.

NOTE: If you are using a unix system, be aware of linebreaks, the OPC uses CRLF not LF.