s-expression/xml isomorphism

After some discussions with Dr. George recently, I was interested in exploring the relationship between xml and s-expressions. This has certainly been done before, but I thought I would try my hand at it. In the end result, I’m able to convert an s-expression such as:

(a :a1 "test" :a2 "test2" "mycdata" (b :a3 "c"))

to xml:

<a a1="test" a2="test2">mycdata<b a3="c"></b></a>

I do so with a somewhat strange but more explicit intermediate format:

(:element-name "a" :attributes (("a1" . "test") ("a2" . "test2")) :cdata nil
                   :children (:element-name "b" :attributes (("a3" . "c"))
                                                   :cdata "My CDATA" :children nil))

This shows pretty clearly how a single namespace xml document can be represented with an s-expression. What I’m wondering now is if I can go from the intermediate representation to something like YAML or JSON. George and I have been calling these ‘tree languages’; I wonder if some sort of overarching equivalence for these ‘tree languages’ can be shown?

I don’t think this has much practical use, but the code is here.

Comments !