XML

The functions gen-xml and parse-xml provide a quick method of going between xml and misc. XML is transformed into MISC by mapping a tag to [tag-name [child1 child2 ...] attribute1:"value" att2:"v2" ...].

[parse-xml "<?xml version=\"1.0\"?> <catalog> <cd title=\"Empire Burlesque\" artist=\"Bob Dylan\" year=\"1985\"/> <cd title=\"Hide your heart\" artist=\"Bonnie Tyler\" year=\"1988\"/> <cd title=\"One night only\" artist=\"Bee Gees\" year=\"1998\"/> </catalog>"]

Once in MISC manipulation is simple. This example gets an array of the cd names.

[mapm /[parse-xml "<?xml version=\"1.0\"?> <catalog> <cd title=\"Empire Burlesque\" artist=\"Bob Dylan\" year=\"1985\"/> <cd title=\"Hide your heart\" artist=\"Bonnie Tyler\" year=\"1988\"/> <cd title=\"One night only\" artist=\"Bee Gees\" year=\"1998\"/> </catalog>"]/1 [lambda '[v:value] '/v/'title]]

More complex transformation are also fairly simple. Like this code which reverses this poem.

[letrec '[ get-child:[lambda '[tag:1 name:2] '[foldm /tag/1 f:[lambda '[v:value r:1] '[if [= name /v/0] then:v else:r]]]] #:"Returns a poem with the title intact and a reversed array of <l> children." transform:[lambda '[mypoem:1] '{'poem title:/[get-child mypoem 'title]/1/0 [reverse [filter-array /mypoem/1 [lambda '[v:value] '[= "l" /v/0]]]]} ] ] '[gen-xml [transform [parse-xml "<?xml version=\"1.0\"?> <poem> <title>Roses are Red</title> <l>Roses are red,</l> <l>Violets are blue;</l> <l>Sugar is sweet,</l> <l>And I love you.</l> </poem>"]] ] ]