core dump on xmlDocFree

13 views
Skip to first unread message

HeLiLiHe

unread,
Mar 3, 2017, 4:09:30 AM3/3/17
to libxml-devel
I'm currently fiddling around with XML handling for the first time, so I'm a newbie to libxml...

Problem: I'm having an xml document in a text buffer (from some other processing), trying to get the root node for it and inserting this as a new node into an outgoing document, so more or less wrapping the incoming XML with some additions to an outgoing XML.

I'm doing (simplyfied)

    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 "info", BAD_CAST "32");
    xmlNewProp(root_node, BAD_CAST "type", BAD_CAST "XER");
    xmlDocSetRootElement(doc, root_node);
   
    /* now add extracted root from input into doc */
    xmlAddChild(root_node, root_node_in);

    /* show me result */
    xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
    printf("XML output has length %i\n", buffersize);
    printf("%s", (char *) xmlbuff);

    xmlFreeDoc(doc);

which works fine and exactly does what I'm expecting.... till xmlFreeDoc ist executed.

What I'm doing wrong? Or other way round - is there a better solution for extracting a node from one XML doc and inserting it into another one?

Greets, Heinz
Reply all
Reply to author
Forward
0 new messages