def element_defs(tags):
    def _padding(type, element):
        return ' ' * (type.max_tagname_len - len(element.name))

    s = ''
    for tag in tags:
        element = tg.elements[tag]
        # no def needed for built-in types
        if element.typename in ('xsd:string'):
            continue
        try:
            type = tg.types[element.typename]
        except __HOLE__:
            continue

        # e.g. blipFill = ElementDef('p:blipFill', 'CT_BlipFillProperties')
        s += ("\n%s = ElementDef('%s', '%s')\n" %
              (element.name, element.tag, element.typename))

        # e.g. blipFill.add_child('a:blip', cardinality='?')
        for child in type.elements:
            s += ("%s.add_child('%s'%s, cardinality='%s')\n" %
                  (element.name, child.tag, _padding(type, child),
                   child.cardinality))

        # e.g. ext.add_attribute('x', required=True, default="0")
        for a in type.required_attributes:
            default = a.default if a.default else ''
            s += ("%s.add_attribute('%s', required=True, default='%s')\n" %
                  (element.name, a.name, default))

        # e.g. xfrm.add_attributes('rot', 'flipH', 'flipV')
        if type.optional_attributes:
            params = "', '".join([a.name for a in type.optional_attributes])
            s += "%s.add_attributes('%s')\n" % (element.name, params)

    return s


# ============================================================================
# main
# ============================================================================
dataset/ETHPy150Open scanny/python-pptx/lab/parse_xsd/parse_xsd.py/element_defs