rsvg_entity_decl (void *data, const xmlChar * name, int type,
                  const xmlChar * publicId, const xmlChar * systemId, xmlChar * content)
{
    RsvgHandle *ctx = (RsvgHandle *) data;
    GHashTable *entities = ctx->priv->entities;
    xmlEntityPtr entity;
#if LIBXML_VERSION >= 20700
    xmlChar *resolvedSystemId = NULL, *resolvedPublicId = NULL;

    if (systemId)
        resolvedSystemId = xmlBuildRelativeURI (systemId, (xmlChar*) rsvg_handle_get_base_uri (ctx));
    else if (publicId)
        resolvedPublicId = xmlBuildRelativeURI (publicId, (xmlChar*) rsvg_handle_get_base_uri (ctx));

    if (type == XML_EXTERNAL_PARAMETER_ENTITY && !content) {
      GByteArray *arr = NULL;

      if (systemId)
        arr = _rsvg_acquire_xlink_href_resource ((const char *) systemId,
                                                 rsvg_handle_get_base_uri (ctx), NULL);
      else if (publicId)
        arr = _rsvg_acquire_xlink_href_resource ((const char *) publicId,
                                                 rsvg_handle_get_base_uri (ctx), NULL);
      if (arr) {
        content = xmlCharStrndup ((const char*)arr->data, arr->len);
        g_byte_array_free(arr, TRUE);
      }
    }
      
    entity = xmlNewEntity(NULL, name, type, resolvedPublicId, resolvedSystemId, content);

    xmlFree(resolvedPublicId);
    xmlFree(resolvedSystemId);

    g_hash_table_insert (entities, g_strdup ((const char*) name), entity);
#else
    xmlChar *dupname;

    entity = xmlMalloc (sizeof (xmlEntity));
    memset (entity, 0, sizeof (xmlEntity));
    entity->type = XML_ENTITY_DECL;
    dupname = (xmlChar *) xmlMemStrdup ((const char *) name);
    entity->name = dupname;

    entity->etype = type;
    if (content) {
        entity->content = (xmlChar *) xmlMemStrdup ((const char *) content);
        entity->length = strlen ((const char *) content);
    } else if (systemId || publicId) {
        GByteArray *data = NULL;

        if (systemId)
            data =
                _rsvg_acquire_xlink_href_resource ((const char *) systemId,
                                                   rsvg_handle_get_base_uri (ctx), NULL);
        else if (publicId)
            data =
                _rsvg_acquire_xlink_href_resource ((const char *) publicId,
                                                   rsvg_handle_get_base_uri (ctx), NULL);

        if (data) {
            entity->SystemID = (xmlChar *) xmlMemStrdup ((const char *) systemId);
            entity->ExternalID = (xmlChar *) xmlMemStrdup ((const char *) publicId);
            entity->content = (xmlChar *) xmlMemStrdup ((const char *) data->data);
            entity->length = data->len;

            /* fool libxml2 into supporting SYSTEM and PUBLIC entities */
            entity->etype = XML_INTERNAL_GENERAL_ENTITY;

            g_byte_array_free (data, TRUE);
        }
    }

    g_hash_table_insert (entities, dupname, entity);
#endif
}
rsvg_entity_decl (void *data, const xmlChar * name, int type,
                  const xmlChar * publicId, const xmlChar * systemId, xmlChar * content)
{
    RsvgHandle *ctx = (RsvgHandle *) data;
    GHashTable *entities = ctx->priv->entities;
    xmlEntityPtr entity;
#if LIBXML_VERSION >= 20700
    xmlChar *resolvedSystemId = NULL, *resolvedPublicId = NULL;

    if (systemId)
        resolvedSystemId = xmlBuildRelativeURI (systemId, (xmlChar*) rsvg_handle_get_base_uri (ctx));
    else if (publicId)
        resolvedPublicId = xmlBuildRelativeURI (publicId, (xmlChar*) rsvg_handle_get_base_uri (ctx));

    if (type == XML_EXTERNAL_PARAMETER_ENTITY && !content) {
      GByteArray *arr = NULL;

      if (systemId)
        arr = _rsvg_acquire_xlink_href_resource ((const char *) systemId,
                                                 rsvg_handle_get_base_uri (ctx), NULL);
      else if (publicId)
        arr = _rsvg_acquire_xlink_href_resource ((const char *) publicId,
                                                 rsvg_handle_get_base_uri (ctx), NULL);
      if (arr) {
        content = xmlCharStrndup ((const char*)arr->data, arr->len);
        g_byte_array_free(arr, TRUE);
      }
    }
      
    entity = xmlNewEntity(NULL, name, type, resolvedPublicId, resolvedSystemId, content);

    xmlFree(resolvedPublicId);
    xmlFree(resolvedSystemId);

    g_hash_table_insert (entities, g_strdup ((const char*) name), entity);
#else
    xmlChar *dupname;

    entity = xmlMalloc (sizeof (xmlEntity));
    memset (entity, 0, sizeof (xmlEntity));
    entity->type = XML_ENTITY_DECL;
    dupname = (xmlChar *) xmlMemStrdup ((const char *) name);
    entity->name = dupname;

    entity->etype = type;
    if (content) {
        entity->content = (xmlChar *) xmlMemStrdup ((const char *) content);
        entity->length = strlen ((const char *) content);
    } else if (systemId || publicId) {
        GByteArray *data = NULL;

        if (systemId)
            data =
                _rsvg_acquire_xlink_href_resource ((const char *) systemId,
                                                   rsvg_handle_get_base_uri (ctx), NULL);
        else if (publicId)
            data =
                _rsvg_acquire_xlink_href_resource ((const char *) publicId,
                                                   rsvg_handle_get_base_uri (ctx), NULL);

        if (data) {
            entity->SystemID = (xmlChar *) xmlMemStrdup ((const char *) systemId);
            entity->ExternalID = (xmlChar *) xmlMemStrdup ((const char *) publicId);
            entity->content = (xmlChar *) xmlMemStrdup ((const char *) data->data);
            entity->length = data->len;

             
            entity->etype = XML_INTERNAL_GENERAL_ENTITY;

            g_byte_array_free (data, TRUE);
        }
    }

    g_hash_table_insert (entities, dupname, entity);
#endif
}