[xml] how to build dom tree with ns decls



Hello,

I want to this document:
------------------------
<?xml version="1.0"?>
<root>
<t1:test xmlns:t1="ns1.test">something iside</t1:test>
</root>
------------------------

but the result which I keep getting is:

------------------------
<?xml version="1.0"?>
<root>
<t1:test>something iside</t1:test>
</root>
------------------------

(the ns decl is missing). I used the code at the end.
Can someone tell me what should I do to have there the namespace declaration
?
Isn't this a problem of the  xmlDocDump function, to produce namespace
declaration attrs. where they are necessary ?

Thanks in advance
Petr

here the code:

------  t1.c  -------
#include <stdio.h>
#include <libxml/tree.h>

int main(int argc, char **argv)
{
 xmlChar* buff;
 int ln;

 xmlDocPtr doc;
 xmlNsPtr ns;
 xmlNodePtr root;
 xmlNodePtr el;

 doc = xmlNewDoc(NULL);
 root = xmlNewDocNode(doc, NULL, "root", NULL);
 xmlAddChild((xmlNodePtr) doc, root);

 ns = xmlNewNs((xmlNodePtr)doc, "ns1.test", "t1");
 el = xmlNewDocNode(doc, ns, "t1:test", "something iside");

 xmlAddChild(root, el);

 xmlDocDumpFormatMemory(doc, &buff, &ln, 1);

 printf(buff);
}
------------------------






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