Re: [xml] Namespaces



Olaf Gellert wrote:
Do I have to add the prefixes by myself? Or did I miss
some libxml2 magic commands? :-)


You missed the magic libxml command "xmlSetNs". You added the namespace to the node, but you didn't tell the node to use the namespace.

root = xmlNewDocNode(document, NULL, (const xmlChar *) "IDMEF-Message", NULL);
idmefNS=xmlNewNs(root, (const xmlChar *) "http://iana.org/idmef";, (const xmlChar *) "idmef");
xmlSetNs(root, idmefNS);


When children are created, they automatically inherit their parents' ns, so as long as you call xmlSetNs before any further children are added, they'll use the prefix too. If you want a child node to NOT use the prefix, just call xmlSetNs(child, NULL).

Jason



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