Meta Data Management

In the meta module contains all classes to access the documents meta data, keywords and user defined tags.

  • Meta class gives you access to the simple meta data
  • Keywords class gives you access to the document keywords
  • Usertags class gives you access to the user defined tags
  • Statistic class gives you access to the document statistics

Every ODF document class has an attribute called meta which is an instance of Meta class.

Meta Class

class meta.Meta

Warning

Don’t create instances of this class by yourself.

You always get/set strings, also for date and time values.

Methods

Meta.__setitem__(key, value)

Set metatag name to value.

Meta.__getitem__(name)

Get metatag name.

You got access to the documents metatags by the subscript operator:

# get values
value = document.meta['generator']
# set values
document.meta['description'] = "This is a text document."

At this time the supported metatags are:

Metatag Description
generator application or tool that was used to create or last modify the XML document.
title title of the document
description brief description of the document
subject subject of the document
initial-creator name of the person who created the document initially
creator name of the person who last modified the document
creation-date date and time when the document was created initially ISO format YYYY-MM-DDThh:mm:ss
date date and time when the document was last modified (ISO format)
editing-cycles number of editing cycles the document has been through. The value of this element is incremented every time the document is saved.
language the document language like 'en-US' or 'de-AT'
Meta.clear()

Delete all metatags, keywords, user-defined tags and statistics.

Attributes

Meta.keywords

The keywords attribute gives you access to the documents keywords by the Keywords class.

Meta.usertags

The usertags attribute gives you access to the documents user defined tags by the Usertags class.

Meta.count

The count attribute gives you access to the documents statistics by the Statistic class.

Keywords Class

class meta.Keywords

The Keywords class manages the <meta:keyword> elements.

Warning

Don’t create instances of this class by yourself.

Methods

Keywords.add(keyword)

Add keyword to the document meta data.

Keywords.remove(keyword)

remove keyword from the document meta data.

Keywords.__iter__()

Iterate over all keywords:

for keyword in document.meta.keywords:
   pass # or do something
Keywords.__contains__(keyword)

True if keyword is in the meta data else False.

This method is used by the in operator:

if 'text' in document.meta.keywords:
    pass # or do something
Keywords.clear()

Delete all keywords.

Usertags Class

class meta.Usertags

The Usertags class manages the <meta:user-defined> elements.

Warning

Don’t create instances of this class by yourself.

Methods

Usertags.set(name, value, value_type=None)

Set the usertag name the value and the type to value_type. The allowed meta types are 'float', 'date', 'time', 'boolean' and 'string'.

Usertags.__setitem__(name, value)

Set usertag name to value, type is 'string'.

Usertags.__getitem__(name)

Get usertag name.

Usertags.__delitem__(name)

Delete usertag name.

usage:

document.meta.usertags['mytag'] = 'text'
value = document.meta.usertags['mytag']
del document.meta.usertags['mytag']
Usertags.typeof(name)

Get type of user defined tag name. The allowed meta types are 'float', 'date', 'time', 'boolean' and 'string'.

Usertags.__contains__(name)

True if the document has a usertag name else False.

This method is used by the in operator:

if 'mytag' in document.meta.usertags:
    pass # or do something
Usertags.__iter__()

Iterate over all usertags, returns 2-tuple (tagname, tagvalue):

for name, value in document.meta.usertags:
   pass # or do something

# create a dict of user defined tags
d = dict(document.meta.usertags)
Usertags.update(d)

Set user defined tags from dict d.

Usertags.clear()

Delete all user defined tags.

Statistic Class

class meta.Statistic

The Statistic class manages the <meta:document-statistic> element.

Warning

Don’t create instances of this class by yourself.

Methods

Statistic.__getitem__(key)

Get count of statistic element key as int, if key is not defined for the document the result is 0.

Statistic.__setitem__(key, value)

Set count of statistic element key to value.

usage:

if document.meta.count['page'] > 3:
    pass # or do something
# or set values
document.meta.count['character'] = 4711
Statistic.__iter__()

Iterate over all statistics, returns 2-tuple (element, value).

create a dict of all statistic values:

d = dict(document.meta.count)
Statistic.update(d)

Set statistics from dict d.

Statistic.clear()

Clear all statistics.

Element Description
page Number of pages in a word processing document. This must be greater than zero. This attribute is not used in spreadsheets. The page-count for a spreadsheet is a calculated value that tells how many sheets have filled cells on them, and this can be zero for a totally empty spreadsheet.
table Number of tables in a word processing document, or number of sheets in a spreadsheet document.
draw Apparently unused in OpenOffice.org2.0
image Number of images in a word processing document.
object Number of objects in a document. This attribute is used in drawing and presentation documents, but it does not bear any simple relationship to the number of items you see on the screen.
ole-object Apparently unused in OpenOffice.org2.0
paragraph Number of paragraphs in a word processing document.
word Number of words in a word processing document.
character Number of characters in a word processing document.
row Apparently unused in OpenOffice.org2.0
frame unknown
sentence Number of sentences in a word processing document.
syllable Number of syllables in a word processing document.
non-whitespace-character Number of non-whitespace-characters in a word processing document.
cell none empty cells in a spreadsheet document.

Table from the online book OASIS OpenDocument Essentials.

Table Of Contents

Previous topic

Document Classes

Next topic

Style management

This Page