part – OfficeDissector - Part Class

A Part of a Document.

class officedissector.part.Part(doc, name)

A Part of a Document.

Variables:
  • 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.

Parameters:
content_type()

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

For information about how Content Types are stored, see: http://office.microsoft.com/en-us/office-open-xml-i-exploring-the-office-open-xml-formats-RZ010243529.aspx?section=16

Returns:the Content Type of this Part
relationships_in()

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

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

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
stream()

Return a file-like object of this Part.

Returns:a file-like object
to_json(include_stream=False)

Export this object to JSON

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

A which uniquely identifies this object.

Returns:string which uniquely identifies this object
xml()

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': "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
>>>                 'dc': "http://purl.org/dc/elements/1.1/",
>>>                 'dcterms': "http://purl.org/dc/terms/",
>>>                 'dcmitype': "http://purl.org/dc/dcmitype/",
>>>                 'xsi': "http://www.w3.org/2001/XMLSchema-instance"}
>>> result = part.xpath('/cp:coreProperties/dcterms:created', CP_NAMESPACE)
>>> result[0].text
'2008-11-03T19:31:00Z'
Parameters:
  • exp (string) – the XPATH expression
  • xmlns (dict) – Optional - the namespace mapping (default: None)
Returns:

the result of the XPATH query.

Previous topic

doc – OfficeDissector - Document Class

Next topic

rel – OfficeDissector - Relationship Class

This Page