summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-06-18 10:47:00 +0100
committerRichard Hughes <richard@hughsie.com>2014-06-18 10:47:00 +0100
commitac8af8e85ce49b7202e3ab67f00136ffc26c8cb6 (patch)
treee5d462552d97418878bc3027e4605ae93d16176f
parent3cf2b09ed6f067fb4488e7d8e8aa8cab42b3f6b5 (diff)
downloadappstream-glib-ac8af8e85ce49b7202e3ab67f00136ffc26c8cb6.tar.gz
Add as_app_to_file()
-rw-r--r--libappstream-glib/as-app.c39
-rw-r--r--libappstream-glib/as-app.h4
2 files changed, 43 insertions, 0 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index efe7d9c..0b27eb6 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -3104,6 +3104,45 @@ as_app_parse_file (AsApp *app,
}
/**
+ * as_app_to_file:
+ * @app: a #AsApp instance.
+ * @file: a #GFile
+ * @cancellable: A #GCancellable, or %NULL
+ * @error: A #GError or %NULL
+ *
+ * Exports a DOM tree to an XML file.
+ *
+ * Returns: %TRUE for success
+ *
+ * Since: 0.2.0
+ **/
+gboolean
+as_app_to_file (AsApp *app,
+ GFile *file,
+ GCancellable *cancellable,
+ GError **error)
+{
+ _cleanup_node_unref_ GNode *root = NULL;
+ _cleanup_string_free_ GString *xml = NULL;
+
+ root = as_node_new ();
+ as_app_node_insert (app, root, 1.0);
+ 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);
+ return g_file_replace_contents (file,
+ xml->str,
+ xml->len,
+ NULL,
+ FALSE,
+ G_FILE_CREATE_NONE,
+ NULL,
+ cancellable,
+ error);
+}
+
+/**
* as_app_new:
*
* Creates a new #AsApp.
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index 0b79b19..1f0998d 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -315,6 +315,10 @@ gboolean as_app_parse_file (AsApp *app,
const gchar *filename,
AsAppParseFlags flags,
GError **error);
+gboolean as_app_to_file (AsApp *app,
+ GFile *file,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS