[dia/dia-0-97] Bug 711418 - Handle diagram file with comments
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/dia-0-97] Bug 711418 - Handle diagram file with comments
- Date: Sat, 8 Mar 2014 12:15:07 +0000 (UTC)
commit 0b4ce87d265870af1df0209c948be3f45082da19
Author: Hans Breuer <hans breuer org>
Date: Sat Dec 14 13:53:41 2013 +0100
Bug 711418 - Handle diagram file with comments
A comment as the first part in the XML file was prohibiting to load
the file at all with “Not a Dia file” error.
(cherry picked from commit 805905eae28f215c74716c1fef684106a9997c54)
app/load_save.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/app/load_save.c b/app/load_save.c
index 2ddd8e2..460057a 100644
--- a/app/load_save.c
+++ b/app/load_save.c
@@ -406,6 +406,7 @@ diagram_data_load(const char *filename, DiagramData *data, void* user_data)
int fd;
GList *list;
xmlDocPtr doc;
+ xmlNodePtr root;
xmlNodePtr diagramdata;
xmlNodePtr paperinfo, gridinfo, guideinfo;
xmlNodePtr layer_node;
@@ -448,28 +449,32 @@ diagram_data_load(const char *filename, DiagramData *data, void* user_data)
dia_message_filename(filename));
return FALSE;
}
-
- if (doc->xmlRootNode == NULL) {
+
+ root = doc->xmlRootNode;
+ /* skip comments */
+ while (root && (root->type != XML_ELEMENT_NODE))
+ root = root->next;
+ if (root == NULL) {
message_error(_("Error loading diagram %s.\nUnknown file type."),
dia_message_filename(filename));
xmlFreeDoc (doc);
return FALSE;
}
- namespace = xmlSearchNs(doc, doc->xmlRootNode, (const xmlChar *)"dia");
- if (xmlStrcmp (doc->xmlRootNode->name, (const xmlChar *)"diagram") || (namespace == NULL)){
+ namespace = xmlSearchNs(doc, root, (const xmlChar *)"dia");
+ if (xmlStrcmp (root->name, (const xmlChar *)"diagram") || (namespace == NULL)){
message_error(_("Error loading diagram %s.\nNot a Dia file."),
dia_message_filename(filename));
xmlFreeDoc (doc);
return FALSE;
}
-
+
/* Destroy the default layer: */
g_ptr_array_remove(data->layers, data->active_layer);
layer_destroy(data->active_layer);
diagramdata =
- find_node_named (doc->xmlRootNode->xmlChildrenNode, "diagramdata");
+ find_node_named (root->xmlChildrenNode, "diagramdata");
/* Read in diagram data: */
data->bg_color = prefs.new_diagram.bg_color;
@@ -616,7 +621,7 @@ diagram_data_load(const char *filename, DiagramData *data, void* user_data)
/* Read in all layers: */
layer_node =
- find_node_named (doc->xmlRootNode->xmlChildrenNode, "layer");
+ find_node_named (root->xmlChildrenNode, "layer");
objects_hash = g_hash_table_new(g_str_hash, g_str_equal);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]