[aravis] dom: add a function for adding xml chunk to an existing document.



commit d7077a07e898390632c0655316889306225243e2
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Apr 2 22:43:28 2012 +0200

    dom: add a function for adding xml chunk to an existing document.

 docs/reference/aravis/aravis-sections.txt |    1 +
 src/arvdomparser.c                        |   47 +++++++++++++++++++++++++----
 src/arvdomparser.h                        |    3 ++
 3 files changed, 45 insertions(+), 6 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 53f61f1..a774e8e 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -1189,6 +1189,7 @@ ArvDomDocumentCreateFunction
 arv_dom_implementation_create_document
 arv_dom_implementation_add_document_type
 arv_dom_implementation_cleanup
+arv_dom_document_append_from_memory
 arv_dom_document_new_from_memory
 arv_dom_document_new_from_path
 arv_dom_document_new_from_url
diff --git a/src/arvdomparser.c b/src/arvdomparser.c
index de59486..5f3befb 100644
--- a/src/arvdomparser.c
+++ b/src/arvdomparser.c
@@ -66,7 +66,6 @@ arv_dom_parser_start_document (void *user_data)
 	ArvDomSaxParserState *state = user_data;
 
 	state->state = STATE;
-	state->document = NULL;
 	state->is_error = FALSE;
 	state->error_depth = 0;
 	state->entities = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, _free_entity);
@@ -264,14 +263,17 @@ typedef enum {
 	ARV_DOM_DOCUMENT_ERROR_INVALID_XML
 } ArvDomDocumentError;
 
-ArvDomDocument *
-arv_dom_document_new_from_memory (const void *buffer, int size, GError **error)
+static ArvDomDocument *
+_parse_memory (ArvDomDocument *document, ArvDomNode *node,
+	       const void *buffer, int size, GError **error)
 {
 	static ArvDomSaxParserState state;
 
-	g_return_val_if_fail (buffer != NULL, NULL);
-
-	state.document = NULL;
+	state.document = document;
+	if (node != NULL)
+		state.current_node = node;
+	else
+		state.current_node = ARV_DOM_NODE (document);
 
 	if (size < 0)
 		size = strlen (buffer);
@@ -292,6 +294,39 @@ arv_dom_document_new_from_memory (const void *buffer, int size, GError **error)
 	return state.document;
 }
 
+/**
+ * arv_dom_document_append_from_memory:
+ * @document: a #ArvDomDocument
+ * @node: a #ArvDomNode
+ * @buffer: a memory buffer holding xml data
+ * @size: size of the xml data, in bytes
+ * @error: an error placeholder
+ *
+ * Append a chunk of xml tree to an existing document. The resulting nodes will be appended to
+ * @node, or to @document if @node == NULL.
+ *
+ * Size set to a negative value indicated an unknow xml data size.
+ */
+
+void
+arv_dom_document_append_from_memory (ArvDomDocument *document, ArvDomNode *node,
+				     const void *buffer, int size, GError **error)
+{
+	g_return_if_fail (ARV_IS_DOM_DOCUMENT (document));
+	g_return_if_fail (ARV_IS_DOM_NODE (node) || node == NULL);
+	g_return_if_fail (buffer != NULL);
+
+	_parse_memory (document, node, buffer, size, error);
+}
+
+ArvDomDocument *
+arv_dom_document_new_from_memory (const void *buffer, int size, GError **error)
+{
+	g_return_val_if_fail (buffer != NULL, NULL);
+
+	return _parse_memory (NULL, NULL, buffer, size, error); 
+}
+
 static ArvDomDocument *
 arv_dom_document_new_from_file (GFile *file, GError **error)
 {
diff --git a/src/arvdomparser.h b/src/arvdomparser.h
index 4eb9e1f..8cbf996 100644
--- a/src/arvdomparser.h
+++ b/src/arvdomparser.h
@@ -29,6 +29,9 @@
 
 G_BEGIN_DECLS
 
+void 			arv_dom_document_append_from_memory 	(ArvDomDocument *document, ArvDomNode *node,
+								 const void *buffer, int size, GError **error);
+
 ArvDomDocument * 	arv_dom_document_new_from_memory 	(const void *buffer, int size, GError **error);
 ArvDomDocument * 	arv_dom_document_new_from_path 		(const char *path, GError **error);
 ArvDomDocument * 	arv_dom_document_new_from_url 		(const char *url, GError **error);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]