diff options
author | Richard Hughes <richard@hughsie.com> | 2018-10-09 15:07:39 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2018-10-09 18:02:46 +0100 |
commit | 72a2e8a1824ba8d41b8bb6f561bc56f703423915 (patch) | |
tree | 27d645f3473c09837fd09ad764848e64e9ab51c1 /libappstream-glib | |
parent | 55e1a51e19119e9b175b7e30c8d43279ff4c301e (diff) | |
download | appstream-glib-72a2e8a1824ba8d41b8bb6f561bc56f703423915.tar.gz |
Add as_app_to_xml()
This allows us to load in a file and export it as AppData XML.
Diffstat (limited to 'libappstream-glib')
-rw-r--r-- | libappstream-glib/as-app.c | 41 | ||||
-rw-r--r-- | libappstream-glib/as-app.h | 2 |
2 files changed, 30 insertions, 13 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index f84011c..01f6d5b 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -6414,6 +6414,31 @@ as_app_parse_file (AsApp *app, const gchar *filename, guint32 flags, GError **er } /** + * as_app_to_xml: + * @app: a #AsApp instance. + * @error: A #GError or %NULL + * + * Exports a DOM tree to an XML string. + * + * Returns: (transfer full): an XML string, or %NULL + * + * Since: 0.7.14 + **/ +GString * +as_app_to_xml (AsApp *app, GError **error) +{ + g_autoptr(AsNodeContext) ctx = as_node_context_new (); + g_autoptr(AsNode) root = as_node_new (); + as_node_context_set_version (ctx, 1.0); + as_node_context_set_output (ctx, AS_FORMAT_KIND_APPDATA); + as_app_node_insert (app, root, ctx); + return as_node_to_xml (root, + AS_NODE_TO_XML_FLAG_ADD_HEADER | + AS_NODE_TO_XML_FLAG_FORMAT_INDENT | + AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); +} + +/** * as_app_to_file: * @app: a #AsApp instance. * @file: a #GFile @@ -6432,19 +6457,9 @@ as_app_to_file (AsApp *app, GCancellable *cancellable, GError **error) { - g_autoptr(AsNodeContext) ctx = NULL; - g_autoptr(AsNode) root = NULL; - g_autoptr(GString) xml = NULL; - - root = as_node_new (); - ctx = as_node_context_new (); - as_node_context_set_version (ctx, 1.0); - as_node_context_set_output (ctx, AS_FORMAT_KIND_APPDATA); - as_app_node_insert (app, root, ctx); - xml = as_node_to_xml (root, - AS_NODE_TO_XML_FLAG_ADD_HEADER | - AS_NODE_TO_XML_FLAG_FORMAT_INDENT | - AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE); + g_autoptr(GString) xml = as_app_to_xml (app, error); + if (xml == NULL) + return FALSE; return g_file_replace_contents (file, xml->str, xml->len, diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h index 425b5c0..3e62b7d 100644 --- a/libappstream-glib/as-app.h +++ b/libappstream-glib/as-app.h @@ -715,6 +715,8 @@ gboolean as_app_to_file (AsApp *app, GFile *file, GCancellable *cancellable, GError **error); +GString *as_app_to_xml (AsApp *app, + GError **error); AsContentRating *as_app_get_content_rating (AsApp *app, const gchar *kind); AsAgreement *as_app_get_agreement_by_kind (AsApp *app, |