def writeDict(d):
    if d:
        writer.beginElement('dict')
        items = (sorted(d.items()) if sort_keys else d.items())
        for (key, value) in items:
            if (not isinstance(key, (str, unicode))):
                if skipkeys:
                    continue
                raise TypeError('keys must be strings')
            writer.simpleElement('key', key)
            writer.writeValue(value)
        writer.endElement('dict')
    else:
        writer.simpleElement('dict')
def writeDict(d):
    if d:
        writer.beginElement('dict')
        items = (sorted(d.items()) if sort_keys else d.items())
        for (key, value) in items:
            if (not isinstance(key, (str, unicode))):
                if skipkeys:
                    continue
                raise TypeError('keys must be strings')
            writer.simpleElement('key', key)
            writer.writeValue(value)
        writer.endElement('dict')
    else:
        writer.simpleElement('dict')