Commit b92c0ccd authored by Matthias Klumpp's avatar Matthias Klumpp
Browse files

Add convenience methods to direcly serialize a component to XML

I expect this to be used quite rarely, but there are some cases where
this is a bit more efficient than going through AsMetadata.
parent 76003d19
...@@ -5291,6 +5291,63 @@ as_component_emit_yaml (AsComponent *cpt, AsContext *ctx, yaml_emitter_t *emitte ...@@ -5291,6 +5291,63 @@ as_component_emit_yaml (AsComponent *cpt, AsContext *ctx, yaml_emitter_t *emitte
g_assert (res); g_assert (res);
} }
/**
* as_component_load_from_xml_data:
* @cpt: an #AsComponent instance.
* @context: an #AsContext instance.
* @data: The XML data to load.
* @error: a #GError.
*
* Load metadata for this component from an XML string.
* You normally do not want to use this method directly and instead use the more
* convenient API of #AsMetadata to create and update components.
*
* Returns: %TRUE on success.
*
* Since: 0.12.10
*/
gboolean
as_component_load_from_xml_data (AsComponent *cpt, AsContext *context, const gchar *data, GError **error)
{
xmlDoc *doc;
xmlNode *root;
gboolean ret;
g_return_val_if_fail (context != NULL, FALSE);
doc = as_xml_parse_document (data, -1, error);
if (doc == NULL)
return FALSE;
root = xmlDocGetRootElement (doc);
ret = as_component_load_from_xml (cpt, context, root, error);
xmlFreeDoc (doc);
return ret;
}
/**
* as_component_to_xml_data:
* @cpt: an #AsComponent instance.
* @context: an #AsContext instance.
* @error: a #GError.
*
* Serialize this component into an XML string.
* You normally do not want to use this method directly and instead use the more
* convenient API of #AsMetadata to serialize components.
*
* Returns: %TRUE on success.
*
* Since: 0.12.10
*/
gchar*
as_component_to_xml_data (AsComponent *cpt, AsContext *context, GError **error)
{
xmlNode *node;
g_return_val_if_fail (context != NULL, NULL);
node = as_component_to_xml_node (cpt, context, NULL);
return as_xml_node_to_str (node, error);
}
/** /**
* as_component_get_desktop_id: * as_component_get_desktop_id:
* @cpt: a #AsComponent instance. * @cpt: a #AsComponent instance.
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define __AS_COMPONENT_H #define __AS_COMPONENT_H
#include <glib-object.h> #include <glib-object.h>
#include "as-context.h"
#include "as-enums.h" #include "as-enums.h"
#include "as-provided.h" #include "as-provided.h"
#include "as-icon.h" #include "as-icon.h"
...@@ -363,6 +364,13 @@ GHashTable *as_component_get_name_table (AsComponent *cpt); ...@@ -363,6 +364,13 @@ GHashTable *as_component_get_name_table (AsComponent *cpt);
GHashTable *as_component_get_summary_table (AsComponent *cpt); GHashTable *as_component_get_summary_table (AsComponent *cpt);
GHashTable *as_component_get_keywords_table (AsComponent *cpt); GHashTable *as_component_get_keywords_table (AsComponent *cpt);
gboolean as_component_load_from_xml_data (AsComponent *cpt,
AsContext *context,
const gchar *data,
GError **error);
gchar *as_component_to_xml_data (AsComponent *cpt,
AsContext *context,
GError **error);
/* DEPRECATED */ /* DEPRECATED */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment