----- Original Message -----
Sent: Tuesday, October 07, 2003 10:24
AM
Subject: [xml] Segmentation fault -
xmlNewDoc
Hi,
I am using libXml to create an xml message and pass on the message to a
webserver. Since I am sending the message as part of a GET request, I remove
all the new line characters from the message. For this I am using a small
helper function which removes all new line characters from the message. My
problem is that the program works fine the first time, however if I try to
construct another xml message I get a segmentation fault. If I do not do any
newline character replacements within the xml string, everything works
fine.
Here is the function I am using
char* constructMessage(const char
*userName,
const char* responsibility)
{
xmlDocPtr doc;
xmlNodePtr
tree, subtree,subsubtree;
xmlChar* Message;
int
size;
char* uid;
uid = (char*)malloc(strlen(userName)*sizeof(char));
strcpy(uid,userName);
encodeData(&uid);
/*construct Message */
doc = xmlNewDoc("1.0");
doc->children = xmlNewDocNode(doc, NULL, "Message", NULL);
xmlSetProp(doc->children,"MessageId","");
xmlSetProp(doc->children,"IntObjectFormat","Hierarchical");
xmlSetProp(doc->children,"MessageType","Integration Object");
xmlSetProp(doc->children,"IntObjectName","User Registration");
tree = xmlNewChild(doc->children, NULL, "Start_UserRegistration",
NULL)
subtree = xmlNewChild(tree, NULL, "UserRegistration",
NULL);
subsubtree = xmlNewChild(subtree, NULL, "FirstName",
uid);
subsubtree = xmlNewChild(subtree, NULL, "LastName",
uid);
subsubtree = xmlNewChild(subtree, NULL, "LoginName",
uid);
subsubtree = xmlNewChild(subtree, NULL,
"ListOfUserRegistration_Responsibilit
", NULL);
tree =
subsubtree;
subtree = xmlNewChild(tree, NULL,
"UserRegistration_Responsibility", NULL);
subsubtree =
xmlNewChild(subtree, NULL, "Responsibility", responsibility);
xmlDocDumpMemory(doc,&Message,&size);
/*helper function*/
replaceChar(&Message,"\n","");
replaceChar(&Message,"
","%20");
xmlFreeDoc(doc);
free(uid);
return
(char*)Message;
}
Am I missing something?
Thanks,
Akshay.
Do you Yahoo!?
The
New Yahoo! Shopping - with improved product
search