[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: S-expressions vs. XML


s expressions
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@f...
>

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.