part – OfficeDissector - Part Class

A Part of a Document.

class officedissector.part.Part(doc, name)

A Part of a Document.

  • doc – the Document object associated with this Part.
  • name – name of Part. Always has a preceding ‘/’ eg. ‘/word/document.xml’
__init__(doc, name)

Initialize the Part.


Determine Content Type of this Part by parsing [Content_Types].xml

For information about how Content Types are stored, see:

Returns:the Content Type of this Part

Determine all Relationship objects for which this part is the target.

>>> doc.part_by_name['/word/document.xml'].relationships_in()[0].target
Returns:list of all Relationships in

Determine all Relationship objects for which this part is the source.

>>> for rel in doc.part_by_name['/word/document.xml'].relationships_out():
>>>     print rel.source
Part [/word/document.xml]
Part [/word/document.xml]
Part [/word/document.xml]
Returns:list of all Relationships out

Return a file-like object of this Part.

Returns:a file-like object

Export this object to JSON

Parameters:include_stream (bool) – Optional - Include base64 encoded stream of this Part (Default false).
Returns:a JSON encoded string

A which uniquely identifies this object.

Returns:string which uniquely identifies this object

Parse the XML of Part.

Returns:an ElementTree of the parsed XML
xpath(exp, xmlns=None)

Evaluate the XPath expression ‘exp’ on the XML of the Part.

To properly understand how to use xpath, see the documentation of XML Namespaces.

The suggested method to use xpath is to provide a user-defined namespace mapping. For example:

>>> CP_NAMESPACE = {'cp': "",
>>>                 'dc': "",
>>>                 'dcterms': "",
>>>                 'dcmitype': "",
>>>                 'xsi': ""}
>>> result = part.xpath('/cp:coreProperties/dcterms:created', CP_NAMESPACE)
>>> result[0].text
  • exp (string) – the XPATH expression
  • xmlns (dict) – Optional - the namespace mapping (default: None)

the result of the XPATH query.

Previous topic

doc – OfficeDissector - Document Class

Next topic

rel – OfficeDissector - Relationship Class

This Page