/* The node is not changed if it (or its first child) is not a custom node. */
int mxmlSetCustom(mxml_node_t *node, void *data, mxml_custom_destroy_cb_t destroy)
/* The node is not changed if it (or its first child) is not a custom node. */
int mxmlSetCustom(mxml_node_t *node, void *data, mxml_custom_destroy_cb_t destroy)
{
  if (node && node->type == MXML_ELEMENT &&
      node->child && node->child->type == MXML_CUSTOM)
    node = node->child;
  if (!node || node->type != MXML_CUSTOM)
    return (-1);
  if (node->value.custom.data && node->value.custom.destroy)
    (*(node->value.custom.destroy))(node->value.custom.data);
  node->value.custom.data    = data;
  node->value.custom.destroy = destroy;
  return (0);
}