[dia] Bug 711418 - Handle diagram file with comments



commit 805905eae28f215c74716c1fef684106a9997c54
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.

 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 72d2e60..70fa280 100644
--- a/app/load_save.c
+++ b/app/load_save.c
@@ -361,6 +361,7 @@ diagram_data_load(const gchar *filename, DiagramData *data, DiaContext *ctx, voi
   int fd;
   GList *list;
   xmlDocPtr doc;
+  xmlNodePtr root;
   xmlNodePtr diagramdata;
   xmlNodePtr paperinfo, gridinfo, guideinfo;
   xmlNodePtr layer_node;
@@ -403,22 +404,26 @@ diagram_data_load(const gchar *filename, DiagramData *data, DiaContext *ctx, voi
     dia_context_add_message(ctx, _("Error loading diagram %s."), 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: */
   if (layer_object_count(data->active_layer) == 0) {
     g_ptr_array_remove(data->layers, data->active_layer);
@@ -426,7 +431,7 @@ diagram_data_load(const gchar *filename, DiagramData *data, DiaContext *ctx, voi
   }
 
   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;
@@ -612,7 +617,7 @@ diagram_data_load(const gchar *filename, DiagramData *data, DiaContext *ctx, voi
   }
   /* 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]