'Add the asset data as XML to the passed-in node.
The node should already be created as a top-level "asset" element.'

@contract(node='AssetElement')
def to_xml(self, node):

    for attr in self.XML_ATTRS:
        child = etree.SubElement(node, attr)
        if (attr == self.ASSET_TYPE_ATTR):
            value = self.asset_id.asset_type
        elif (attr == self.ASSET_BASENAME_ATTR):
            value = self.asset_id.path
        else:
            value = getattr(self, attr)
        if isinstance(value, bool):
            value = ('true' if value else 'false')
        elif isinstance(value, datetime):
            value = value.isoformat()
        elif isinstance(value, dict):
            value = json.dumps(value)
        else:
            value = unicode(value)
        child.text = value
