Example #1
0
 def to_tree(self, tagname=None, value=None, namespace=None):
     namespace = getattr(self, "namespace", namespace)
     if namespace is not None:
         tagname = "{%s}%s" % (namespace, tagname)
     el = Element(tagname)
     if value is not None:
         el.text = datetime_to_W3CDTF(value)
         return el
Example #2
0
def write_properties(props):
    """Write the core properties to xml."""
    root = Element('{%s}coreProperties' % COREPROPS_NS)
    for attr in ("creator", "title", "description", "subject", "identifier",
                 "language"):
        SubElement(root, '{%s}%s' % (DCORE_NS, attr)).text = getattr(props, attr)

    for attr in ("created", "modified"):
        value = datetime_to_W3CDTF(getattr(props, attr))
        SubElement(root, '{%s}%s' % (DCTERMS_NS, attr),
                   {'{%s}type' % XSI_NS:'%s:W3CDTF' % DCTERMS_PREFIX}).text = value

    for attr in ("lastModifiedBy", "category", "contentStatus", "version",
                 "revision", "keywords"):
        SubElement(root, '{%s}%s' % (COREPROPS_NS, attr)).text = getattr(props, attr)

    if props.lastPrinted is not None:
        SubElement(root, "{%s}lastPrinted" % COREPROPS_NS).text = datetime_to_W3CDTF(props.lastPrinted
                                                                            )
    return tostring(root)