I'm quite new to libxml usage, but it seems to be a handy way to deal with XML 
documents solving my problem. I thought at least :-)

My little problem to solve: I'm getting some input XML doc (each with one out 
of several possible root elements) , shall wrap this into a "cover document" by 
adding some control information to it and hand over the "wrapper XML" to the 
next processing step.

For a proof of concept I've been starting with this:

   doc_in = xmlReadMemory(msg_xml, strlen(msg_xml), NULL, NULL, 0);
   root_node_in = xmlDocGetRootElement(doc_in);

   doc = xmlNewDoc(BAD_CAST "1.0");
   root_node = xmlNewNode(NULL, BAD_CAST "received");
   xmlNewProp(root_node, BAD_CAST "time", BAD_CAST "2017-03-01 17:57:21");
   xmlNewProp(root_node, BAD_CAST "from", BAD_CAST "32"); 
   xmlNewProp(root_node, BAD_CAST "type", BAD_CAST "control"); 
   xmlDocSetRootElement(doc, root_node);
        
   /* now add extracted node from input to new doc */
   xmlAddChild(root_node, root_node_in); /* <<--- causes the problem */

   /* show me result */
   xmlDocDump(stdout, doc_in);
   xmlDocDump(stdout, doc);
   xmlFreeDoc(doc); /* <<--- where it crashes */

the result is perfectly fitting my expectations, till I hit the xmlDocFree 
statement giving me 
*** Error in `./main2': free(): invalid pointer: 0x099680de ***
Aborted (core dumped)

I've tried to check every pointer, the one indicated isn't visible to me at 
all...
>From value range my expectation is it's somewhere in the control structure of 
>doc.
If I leave out the node insertion there is no error on freeing the doc(s). 
To be honest I have no clue what I'm doing wrong, but it seems I haven't 
understood internal behavior of libxml yet :-(

Any helpful ideas? Is there be a better way doing this? 
I'm trying not to produce much overhead and trying not to parse XML myself ;-)

Thanks,
Heinz



The information contained in this e-mail message is privileged and confidential 
and is for the exclusive use of the addressee. The person who receives this 
message and who is not the addressee, one of his employees or an agent entitled 
to hand it over to the addressee, is informed that he may not use, disclose or 
reproduce the contents thereof, and is kindly asked to notify the sender and 
delete the e-mail immediately.

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml

Reply via email to