武义建设工程网站,手表网站模板,企业邮箱登录入口126,深圳线上网络推广公司引言
Relationships由一系列Relationship构成。将Abstract Package看做是一个图数据结构#xff0c;则Relationships是图数据中的边集合。
Package Relationships
对于Package Relationships#xff0c;其所有引用关系的source对象为Abstract Package#xff0c;或者看…引言
Relationships由一系列Relationship构成。将Abstract Package看做是一个图数据结构则Relationships是图数据中的边集合。
Package Relationships
对于Package Relationships其所有引用关系的source对象为Abstract Package或者看做是Abstract Package的一个虚拟根节点。target为包内的其它part节点或者外部资源。Package Relationships定义于/_rel/.rels.xml文件中。其中首部的“/”表示包根路径。一个简单/_rel/.rels.xml文件内容实例
?xml version1.0 encodingUTF-8 standaloneyes?
Relationships xmlnshttp://schemas.openxmlformats.org/package/2006/relationshipsRelationship IdrId3 Typehttp://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties TargetdocProps/core.xml/Relationship IdrId2 Typehttp://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail TargetdocProps/thumbnail.emf/Relationship IdrId1 Typehttp://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument Targetword/document.xml/Relationship IdrId4 Typehttp://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties TargetdocProps/app.xml/
/RelationshipsPart Relationships
对于Part Relationships类型。包内part节点可能会引用包内另外的part节点或者包外资源。对于某一节点如果其作为source对象并存在1或者多个Part Relationship类型引用则会在该节点下创建一个“_rel”目录并在其中创建一个_rels.xml文件。例如/docProps/core.xml part节点并没有引用其它资源 则/docProps目录下不存在“rels.xml”文件。而/word/document.xml part节点通常需要引用其它资源这部分引用信息存储在 word/_rels/document.xml.rels 中。 以下为一个简单的/word/_rels/document.xml.rels文件内容实例 ?xml version1.0 encodingUTF-8 standaloneyes?Relationships xmlnshttp://schemas.openxmlformats.org/package/2006/relationshipsRelationship IdrId3 Typehttp://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings TargetwebSettings.xml/Relationship IdrId2 Typehttp://schemas.openxmlformats.org/officeDocument/2006/relationships/settings Targetsettings.xml/Relationship IdrId1 Typehttp://schemas.openxmlformats.org/officeDocument/2006/relationships/styles Targetstyles.xml/Relationship IdrId6 Typehttp://schemas.openxmlformats.org/officeDocument/2006/relationships/theme Targettheme/theme1.xml/Relationship IdrId5 Typehttp://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable TargetfontTable.xml/Relationship IdrId4 Typehttp://schemas.openxmlformats.org/officeDocument/2006/relationships/image Targetmedia/image1.jpeg//Relationships注意不论是Package Relationships 或者Part Relationshipssource都是唯一的但target是多样的。 Each set of relationships sharing a common source is represented by a Relationships part. .rels.xml文件解析
Relationships以XML 文件格式存储其根节点元素为复杂类型complex type CT_Relationships。根节点下存储的每一子节点元素为 CT_Relationship。CT_Relationship包含四个属性值
- target mode该属性为optional默认取值internal。当target为外部资源时为external target mode当target为包内资源时为internel target mode。
- target 该属性为required。如果为internel target mode则target属性值为相对引用信息。
- type, 该属性为required。relationship type 可以以URI形式进行相互比较的。
- id 该属性为required。为relationship的唯一标识符在一个Relationships内rid具有唯一性。在docx.opc.oxml.CT_Relationship的实例化定义如下
class CT_Relationship(BaseOxmlElement):Relationship element, representing a single relationship from asource to a target part.staticmethoddef new(rId, reltype, target, target_modeRTM.INTERNAL):Return a new Relationship element.xml Relationship xmlns%s/ % nsmap[pr]relationship parse_xml(xml)relationship.set(Id, rId)relationship.set(Type, reltype)relationship.set(Target, target)if target_mode RTM.EXTERNAL:relationship.set(TargetMode, RTM.EXTERNAL)return relationship总结
基于Abstract Package Model从docx文档抽取一个Abstract Package计算程序要做的第一步便是读取“/_rel/.rels.xml” Package Relationships 引用关系文件从而确定虚拟根节点的直接子节点。然后根据“/[Content_Types].xml”分别处理每个直接子节点的xml文件。在处理子节点part对象时同样会检查该子节点是否包含Part Relationships如果包含则创建一颗子树。不断迭代该过程并最终将直接子节点与包虚拟根节点连接起来从而完成Abstract Package抽取。因此创建子节点、加载引用关系是一个“深度优先遍历”过程。 参考资料
《ISO/IEC 29500-2Open packaging conventions》