opc简介
- OPC(Open Packaging Conventions)定义于“ISO/IEC 29500-2”1。“ISO/IEC 29500” 包含4个文件,构成了Office Open XML标准,OPC是Open XML 标准的第二个文件。
- OPC是一种文件包装格式,由微软创建,用于存储组合XML和非XML文件,这些文件共同组成一个单一实体Package,也可称为“包”。这种格式保留了独立文件实体,使得文件体积相较于正常使用XML的情况大大减小。
- OPC主要用于Microsoft Office系统中的文档格式,它将文档内容、样式和配置信息分开存储,从而实现了文档的模块化。有助于提高文档的兼容性和可扩展性,使得不同应用程序和平台之间能够方便地共享和处理文档。
- OPC遵循ZIP压缩格式,将文档分解为多个部分(Parts),每个部分包含特定的信息或对象。例如,在一个演示文稿中,每个幻灯片都作为一个部分存储。部分之间通过关系(Relationships)相互关联。
- OPC中最重要的三个概念abstract package, part, relationship。
重要概念
byte
sequence of 8 bits treated as a unit
Byte是字节,Bit是计算机二进制基本单位,Byte字节由8个Bits组成。
stream
linearly ordered sequence of bytes
线性有序的字节流。
abstract package
logical entity that holds a collection of parts and relationships.
可以将part看成抽象包(abstrat package)中的一个节点, relationship作为节点之间的一条边,abstract package作为一个虚拟的根节点。整个abstract package类似一个图数据结构。官方文档给出了一个生动的抽象包图例:
part
stream with a name, a MIME media type and associated common properties.
包节点2需要指定在包范围内唯一的名称,MIME类型——以便告知程序如何处理该节点包含的字节流,字节流,以及与该节点关联的关系边集合。简单点理解,将包节点看做是包内一个独立的XML文件或者非XML文件。
relationship
package relationship or part relationship. package relationship is that connection from a package to a specific part in the same package, or to an external resource. part relationship is that connection from a part in a package to another part in the same package, or to an external resource.
- 关系分类包级别(package-level)的关系与节点级别(part-level)的关系。
- 关系边将包节点连接起来,使得用户可以通过虚拟根节点访问任意包节点。
source
part or package from which a connection is established by a relationship.
关系边的起始端节点。该节点可以是包内节点或者包根节点。
target
part or external resource to which a connection is established by a relationship.
关系边的终止端节点。该节点可以是包内节点或者外部资源。
relationship type
absolute IRI for specifying the role of a relationship.
关系类型指明该关系的“校色”。
Relationships part
part containing an XML representation of relationships.
记录关系边集合的XML文件,一般定义于rels格式文件。例如包级别的关系信息记录于“_rels/.rels”文件。注意一个rels格式文件一般记录多条关系边信息,因此在OPC中通常使用Relationships容器来封装Relationship元素。以下是一个简单的示例:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/package/2006/relationships" Target="word/document.xml"/>
<!-- 更多关系定义 -->
</Relationships>
在这个示例中,属性值Id等于"rId1"的Relationship元素是Relationships的一个子元素,Type属性值为"http://schemas.openxmlformats.org/package/2006/relationships",表示这是一个包级别关系。Target属性值"word/document.xml"表示该关系的目标部分为"word/document.xml"。
physical package
physical package is result of mapping an abstract package to a physical format.
physical package 是将abstract package存储为指定格式的结果文件。如zip、docx、xlsx、pptx等格式文件。官方给出了一个物理包图例说明:
Media Types stream
stream in a physical package representing an XML document that specifies the media type
of each part in the package.
part的MIME类型,一般定义于"/[Content_Types].xml”文件中。