redefinition of namespaces works
In one of the previous entries I wrote that conversion of namespaces is mostly working, but in some cases doesn't. I've traced the reason, and it neither a bug in my code, neither a bug in libxml2. It's just an interference of features.
I fix up namespace definitions after possible use of these namespaces. If a namespace prefix is used before the actual definition, the code creates a temporary namespace definition in which URI is NULL.
At the moment of fixup, the code doesn't know if a definition was created or not. So the initial codeflow was as follows. Suppose that there is no definition yet and use "xmlNewNs" to create a new one. If it returns NULL, it means that the definition is already created. In this case I use "xmlSearchNs" to find this definition.
But "xmlSearchNs" also returns NULL! The problem is that a namespace definition with URI set to NULL is invalid, and "xmlSearchNs" seems check it and return NULL instead of the namespace definition itself. Maybe it's reasonable, but it's bad for me.
Now, instead of using "xmlSearchNs", I manually walk over "nsDef" list. The conversion works now. SXML:
(e1 (@ (ns:a1 "a1") (@ (*NAMESPACES* (ns "myns")))) (e2 (@ (ns:a2 "a2") (@ (*NAMESPACES* (ns "yours")))))))
XML:
<e1 xmlns:ns="myns" ns:a1="a1"> <e2 xmlns:ns="yours" ns:a2="a2"/> </e1>