Re: [xml] question on namespace



On Fri, 2004-04-23 at 08:29, Chris sun wrote:
Hi :
   I have the following code to create xml doc.
 
xmlDocPtr doc;
xmlNsPtr nsp;
xmlNodePtr root;
 
doc = xmlNewDoc(BAD_CAST "1.0");
nsp = xmlNewNs(NULL, BAD_CAST http://www.mycompany.com/NAME, NULL);
root = xmlNewNode(nsp, BAD_CAST "root_node");
xmlDocSetRootElement(doc, root);
......
The newly created file doesn't have namespace tag on it's root
element. 
so if I open this file and validate , it will fail. 
I wonder why the default namespace I specified was saved into xml file
? 
 

Try reversing the order you call xmlNewNS and xmlNewNode:
        root = xmlNewNode(NULL, BAD_CAST "root_node");
        nsp = xmlNewNs(root, BAD_CAST "http://www.mycompany.com/NAME";, NULL);

Cheers,
John





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