[gdome]gdome_doc_importNode leaves the imported node with no document



hi,

when I use gdome_doc_importNode the node doesn't seem to be imported
properly. Its document is set to NULL. Therefore trying to insert the
returned node with gdome_n_insertBefore fails with a WRONG_DOCUMENT_ERR (no
4).

Here is what I'm doing in case it is my mistake(I'm setting the document
manually as after importing it is NULL). It is the deserialization and
insertion of a node copied from the clipboard.

btw is writing my own import function that doesn't copy the node as simple
as changing the document element in all the nodes?

void selectionReceived_cb(GtkWidget *self, 
                                       GtkSelectionData *selection_data,
                                       gpointer data)
{
  GdomeNode *pastedDn = NULL;
  GdomeNode *parentDn = NULL;

  if (selection_data->length < 0)
    {
      g_printerr ("Selection retrieval failed\n");
      return;
    }

  parentDn = getSelectedDn(self);

  pastedDn = deSerializeDn(self,
				               selection_data->data,
                                       selection_data->length,
                                       gdome_n_ownerDocument(parentDn,
&exc));
  if(pastedDn == NULL)
    {
      g_printerr("Deserializing pasted node failed");
      return;
    }

   //This is needed as the document is NULL. Should probably be recursive
but haven't checked
  gdome_xml_n_get_xmlNode(pastedDn)->doc =
gdome_xml_n_get_xmlNode(parentDn)->doc;
  
  gdome_n_insertBefore(parentDn,
                                  pastedDn, 
                                  gdome_n_firstChild(parentDn,&exc),
                                  &exc);
  if (exc != 0)
    {
      g_printerr("Insert node :failed\n\tException #%d\n", exc);
      exc = 0;
      return;
    }
  
}

static GdomeNode* deSerializeDn(GtkWidget *self,
                                                 gchar *xml,
                                                 gint length,
                                                 GdomeDocument
*thisGdomeDoc)
{
  xmlDocPtr xmlDoc;
  GdomeDocument *gdomeDoc;
  GdomeNode *rootDn;
  GdomeNode *importedDn;
  
  xmlDoc = xmlParseMemory(xml, length);
  gdomeDoc = gdome_xml_from_document(xmlDoc);
  rootDn = (GdomeNode *)gdome_doc_documentElement(gdomeDoc, &exc);
  importedDn = gdome_doc_importNode(thisGdomeDoc, rootDn, TRUE, &exc);
  if (exc != 0)
    {
      g_printerr("Import node :failed\n\tException #%d\n", exc);
      exc = 0;
      return NULL;
    }

  //is this the correct way to get rid of the doc?
  //does it also free the xmlDoc?
  gdome_doc_unref (gdomeDoc, &exc);

  return importedDn;
}

thanks rob





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