Docx 或 XPS(或一般的 ooxml)关系转换示例
Docx or XPS(or ooxml in general) Relationship transform example
嗯,我已经知道有一份关于此的文档,其中指出:
12.2.4.26 Relationships Transform Algorithm
13 The relationships transform takes the XML document from the Relationships part and converts it to another
14 XML document.
15 The package implementer might create relationships XML that contains content from several namespaces, along
16 with versioning instructions as defined in Part 5: “Markup Compatibility and Extensibility”. [O6.11]
17 The relationships transform algorithm is as follows:
18 Step 1: Process versioning instructions
19 1. The package implementer shall process the versioning instructions, considering that the only known
20 namespace is the Relationships namespace.
21 2. The package implementer shall remove all ignorable content, ignoring preservation attributes.
22 3. The package implementer shall remove all versioning instructions.
23 Step 2: Sort and filter relationships
24 1. The package implementer shall remove all namespace declarations except the Relationships namespace
25 declaration.
26 2. The package implementer shall remove the Relationships namespace prefix, if it is present.
27 3. The package implementer shall sort relationship elements by Id value in lexicographical order,
28 considering Id values as case-sensitive Unicode strings.
29 4. The package implementer shall remove all Relationship elements that do not have eitheran Id value
30 that matches any SourceId valueor a Type value that matches any SourceType value, among the
31 SourceId and SourceType values specified in the transform definition. Producers and consumers shall
32 compare values as case-sensitive Unicode strings. [M6.27] The resulting XML document holds all
33 Relationship elements that either have an Id value that matches a SourceId value or a Type value that
34 matches a SourceType value specified in the transform definition.
35 Step 3: Prepare for canonicalization
Digital Signatures
58
1. The package implementer shall remove all characters between the 1 Relationships start tag and the first
2 Relationship start tag.
3 2. The package implementer shall remove any contents of the Relationship element.
4 3. The package implementer shall remove all characters between the last Relationship end tag and the
5 Relationships end tag.
6 4. If there are no Relationship elements, the package implementer shall remove all characters between
7 the Relationships start tag and the Relationships end tag.
但是我在这个过程中有点困惑,因为在每次尝试中我都会重现不正确的转换,即使据说我已经遵守了文档中的所有规范,
也许如果只有一个这种转换的例子(只有输入 => 输出),我就不会那么困惑了。所以这里唯一需要的是这样的包特定 xml 函数的例子(或者可选地,有一个答案和代码虽然不是必需的,因为我已经开发了大部分。)
下面是试图生成输出的标签:
<Reference URI="/Documents/1/Pages/_rels/1.fpage.rels?ContentType=application/vnd.openxmlformats-package.relationships+xml"><Transforms><Transform Algorithm="http://schemas.openxmlformats.org/package/2006/RelationshipTransform"><opc:RelationshipReference SourceId="rId1" /></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /></Transforms></Reference>
这是原始关系文件:
<?xml version="1.0" encoding="utf-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="/Documents/1/Pages/3.xml" Id="rId3" /><Relationship Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="/Documents/1/Pages/2.xml" Id="rId2" /><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="/Documents/1/Pages/1.xml" Id="rId1"/></Relationships>
这是(错误地)转换的一个:
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Target="/Documents/1/Pages/1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"></Relationship></Relationships>
我已经在这里回答了这个问题:
TL;DR
您忘记了关系转换中的“准备规范化”步骤,并且没有将“TargetMode”属性添加到“Relationship" 元素。
嗯,我已经知道有一份关于此的文档,其中指出:
12.2.4.26 Relationships Transform Algorithm
13 The relationships transform takes the XML document from the Relationships part and converts it to another
14 XML document.
15 The package implementer might create relationships XML that contains content from several namespaces, along
16 with versioning instructions as defined in Part 5: “Markup Compatibility and Extensibility”. [O6.11]
17 The relationships transform algorithm is as follows:
18 Step 1: Process versioning instructions
19 1. The package implementer shall process the versioning instructions, considering that the only known
20 namespace is the Relationships namespace.
21 2. The package implementer shall remove all ignorable content, ignoring preservation attributes.
22 3. The package implementer shall remove all versioning instructions.
23 Step 2: Sort and filter relationships
24 1. The package implementer shall remove all namespace declarations except the Relationships namespace
25 declaration.
26 2. The package implementer shall remove the Relationships namespace prefix, if it is present.
27 3. The package implementer shall sort relationship elements by Id value in lexicographical order,
28 considering Id values as case-sensitive Unicode strings.
29 4. The package implementer shall remove all Relationship elements that do not have eitheran Id value
30 that matches any SourceId valueor a Type value that matches any SourceType value, among the
31 SourceId and SourceType values specified in the transform definition. Producers and consumers shall
32 compare values as case-sensitive Unicode strings. [M6.27] The resulting XML document holds all
33 Relationship elements that either have an Id value that matches a SourceId value or a Type value that
34 matches a SourceType value specified in the transform definition.
35 Step 3: Prepare for canonicalization
Digital Signatures
58
1. The package implementer shall remove all characters between the 1 Relationships start tag and the first
2 Relationship start tag.
3 2. The package implementer shall remove any contents of the Relationship element.
4 3. The package implementer shall remove all characters between the last Relationship end tag and the
5 Relationships end tag.
6 4. If there are no Relationship elements, the package implementer shall remove all characters between
7 the Relationships start tag and the Relationships end tag.
但是我在这个过程中有点困惑,因为在每次尝试中我都会重现不正确的转换,即使据说我已经遵守了文档中的所有规范,
也许如果只有一个这种转换的例子(只有输入 => 输出),我就不会那么困惑了。所以这里唯一需要的是这样的包特定 xml 函数的例子(或者可选地,有一个答案和代码虽然不是必需的,因为我已经开发了大部分。)
下面是试图生成输出的标签:
<Reference URI="/Documents/1/Pages/_rels/1.fpage.rels?ContentType=application/vnd.openxmlformats-package.relationships+xml"><Transforms><Transform Algorithm="http://schemas.openxmlformats.org/package/2006/RelationshipTransform"><opc:RelationshipReference SourceId="rId1" /></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /></Transforms></Reference>
这是原始关系文件:
<?xml version="1.0" encoding="utf-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="/Documents/1/Pages/3.xml" Id="rId3" /><Relationship Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="/Documents/1/Pages/2.xml" Id="rId2" /><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="/Documents/1/Pages/1.xml" Id="rId1"/></Relationships>
这是(错误地)转换的一个:
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Target="/Documents/1/Pages/1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"></Relationship></Relationships>
我已经在这里回答了这个问题:
TL;DR 您忘记了关系转换中的“准备规范化”步骤,并且没有将“TargetMode”属性添加到“Relationship" 元素。