OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] S-expressions vs. XML

[ Lists Home | Date Index | Thread Index ]

On Monday 06 January 2003 7:59 pm, you wrote:
> Mike Champion wrote:
> > Actually, since S-expressions are isomorphic to the basic XML data model,
> > one could argue that X# == LISP :-)
>
> I've heard this claim asserted many, many times,
> but I still don't believe it.
>
> Can anyone demonstrate the isomorphism?  That is,
> come up with a pair of functions f :: S-Exp -> XML
> and g :: XML -> S-Exp such that (f . g) = id_{XML}
> and (g . f) = id_{S-Exp}?
>
> Note that any such pair of functions must also satisfy
> h(x) = f(g(h(x))) = h(f(g(x))) for all x :: XML and
> h :: XML -> XML, including, for example,
> h = XPath(ancestor::*/following-sibling::*).

There's some variation in how one might handle attributes, but going with the 
de facto standard for keyword arguments in s-exprs one might say:

<e a="b" c="d">[...]</e> -> (e a: "b" c: "d" [...])

Some cdata -> "Some cdata"

<!-- Comment --> -> (#comment "Comment")

<?foo bar?> -> (#pi "foo" "bar")

And special rules to deal with stuff that XML lacks and s-exprs have:

<sexpr:symbol name="*" /> -> *
<sexpr:number value="123" /> -> 123

Note that since you don't get elements with names starting # in XML I have 
used those 'invalid' sequences to represent comments and PIs in s-exprs - one 
could use real s-expr comments but then they get discarded on parsing which 
isn't quite XML, so there's a slight hole in the isomorphism there, one might 
argue.

Oh, and as for the document itself; if it's just a root element then use the 
element rule above, otherwise:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE foo SYSTEM "bar" PUBLIC "baz" [wibble]>
[...]

->

(#xml version: "1.0" encoding: "utf-8" doctype-system: "bar" doctype-public: 
"baz" internal-dtd: "wibble" [...])

Does that cover everything apart from differing sets of allowed characters? 
Those can be messy. As it stands there are lots of symbols that cannot map to 
XML element or attribute names, in which case we might need to use more stuff 
from the sexpr: namespace...

<sexpr:element name="*">
  <sexpr:attribute name="+" value="123" />
  ...
</sexpr:element>

->

(* +: 123 ...)

I think anything allowed in an XML element or attribute name will be a valid 
symbol - whitespace, brackets, "," and "`" are about all you need to worry 
about.

Not a super formal definition there but I think it could be tidied up to what 
you want.

Any blatant errors jump out at you? It's nearly 1am here so be nice :-)

>
> --Joe English
>
>   jenglish@flightlab.com
>

ABS

-- 
Oh, pilot of the storm who leaves no trace, Like thoughts inside a dream
Heed the path that led me to that place, Yellow desert screen




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS