Re: [xml] Dump document to a buffer without xml version



I have find a solution/workaround by using xmlNodeDump with the root node:

xmlBufferPtr buf = xmlBufferCreate();
int size = xmlNodeDump(buf, doc, node, 0, 0);
printf ("%s\n", buf->content);
xmlBufferFree (buf);

I'm not sure if it is the correct way to do it thought.

Best regards,


2014-08-20 19:04 GMT+02:00 Iñigo Martínez <inigomartinez gmail com>:
Hi:

I'm working with a protocol based on XML, something like:

<Command Timestamp="0" ReceptionTimeStamp="0" Sender="P1"
Receiver="P2"><GetData/></Command>

I can successfully parse these messages using xmlReadMemory and
navigating through the tree. When trying to create my own messages I
can create them successfully this way:

doc = xmlNewDoc(NULL);
node = xmlNewNode(NULL, BAD_CAST "Command");
xmlDocSetRootElement(doc, node);

xmlNewProp(node, BAD_CAST "Timestamp", BAD_CAST "0");
xmlNewProp(node, BAD_CAST "ReceptionTimestamp", BAD_CAST "0");
xmlNewProp(node, BAD_CAST "Sender", BAD_CAST "P1");
xmlNewProp(node, BAD_CAST "Receiver", BAD_CAST "P2");

xmlNewChild(node, NULL, BAD_CAST "GetData", NULL);

The problem comes when trying to get the correspondant string as I get
the xml version in the output:

<?xml version="1.0"?><Command Timestamp="0" ReceptionTimeStamp="0"
Sender="P1" Receiver="P2"><GetData/></Command>

I have seen some tricks using a xmlTextWriter, but in my case I need
an string not a file.

Is there any way to avoid it ?

Thank you,

Best regards,


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