Surprisingly, conversion from libxml2 tree to SXML seems a trivial task now. Only attributes and namespaces are left.
The core of the conversion engine is a set of self-recursive procedures. It took some time to implement them for the unnecessary (I though so at the moment) goal of conversion of the document node (*TOP* in SXML). But having the procedures, the whole tree of elements was converted with help of a few C lines.
* conversion works for: document nodes, comments, processing instructions;
* basically works for elements, but without attributes and namespaces;
* TODO: attributes and namespaces.
I hope to finish "TODO" in one work block.
But I have to fix bugs first.
The first issue probably is not a bug. While coding the conversion (XML to SXML), I forgot about the internal XML-SXML map, and was converting the same XML node several times. It's fixed now, but I want to check that I did't forget to use the map in the reverse (SXML to XML) conversion.
The second issue is definitely not a bug, but it still worth checking. Is it possible to create comment or PI with NULL (not empty string!) content using SXML to XML conversion?
The real bug is coredumping on a certain construction. I stopped programming when I got coredump and can't say for sure, but I think I know the reason and solution in advance.