[xml] Regarding Adding namespace prefix to the Root Element

Hi All,

I want to generate a XML like the following , In this example root element Envelope having namespace prefix as "S11" . How to add the namespace prefix to the Root Element. In my code below I have simply given Root element name as "S11:Envelope", I know it is wrong, Please let me know the correct way to do it.

<?xml version="1.0"?>
<S11:Envelope xmlns:S11="..." xmlns:wsu="..." xmlns:wsse="..." xmlns:xenc="..." xmlns:wst="...">


 doc = xmlNewDoc(BAD_CAST "1.0");
    root = xmlNewNode(NULL, BAD_CAST "S11:Envelope");
    ns = xmlNewNs(root,"...","S11");
    ns1 = xmlNewNs(root,"...","wsu");
    ns2 = xmlNewNs(root,"...","wsse");
    ns3 = xmlNewNs(root,"...","xenc");
    ns4 = xmlNewNs(root,"...","wst");

    /* Create some nodes */
    node = xmlNewChild(root, ns, BAD_CAST "Header", NULL);
    node1 = xmlNewChild(node, ns2, BAD_CAST "Security", NULL);
    node2 = xmlNewChild(node1, ns2, BAD_CAST "UsernameToken", NULL);
     xmlNewChild(node2, ns2, BAD_CAST "Username", "appx_username");
    xmlNewChild(node2, ns2, BAD_CAST "Password", "password");

    xmlDocSetRootElement(doc, root);

    /* Dump the document to a buffer and print it for demonstration purposes. */
    xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
    xml = (char*)xmlbuff;
    printf("\nThe created document:\n%s\n",xml);


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