[xml] self-defined namespace nodes



I need a bit of help with use of namespaces in the xml tree creation interface (xmlNewDoc et al.). Specifically, I need to be able to create a an xml root element in a self-defined namespace, like this:

<h:html xmlns:h="http://www.w3.org/HTML/1998/html4";>
something...
</h:html>

Per the api, to create the root element with a namespace, I've gotta call xmlNewNode with an xmlNs* argument. But to create an xmlNs, i need to call xmlNewNs, which needs the xml element where we want the xmlns tag to be added (the root element in this case, which we haven't created yet). What is the indended way of creating such an element using the libxml2 tree api?

My present cowardly code includes the namespace in the name, like:

xmlNode* rootelem = xmlNewNode(NULL, (xmlChar *) "h:html");
xmlNs* hNs = xmlNewNs(rootelem,
              (xmlChar *) "http://www.w3.org/HTML/1998/html4";,
              (xmlChar *) "h");

But ideally, I should be calling
xmlNode* rootelem = xmlNewNode(hNs, (xmlChar *) "html");
which I cant.

Thanks,
roop.



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