<s>
A	O
Canonical	O
S-expression	B-Protocol
(	O
or	O
csexp	B-Protocol
)	O
is	O
a	O
binary	O
encoding	O
form	O
of	O
a	O
subset	O
of	O
general	O
S-expression	B-Protocol
(	O
or	O
sexp	B-Protocol
)	O
.	O
</s>
<s>
It	O
was	O
designed	O
for	O
use	O
in	O
SPKI	O
to	O
retain	O
the	O
power	O
of	O
S-expressions	B-Protocol
and	O
ensure	O
canonical	O
form	O
for	O
applications	O
such	O
as	O
digital	O
signatures	O
while	O
achieving	O
the	O
compactness	O
of	O
a	O
binary	O
form	O
and	O
maximizing	O
the	O
speed	O
of	O
parsing	O
.	O
</s>
<s>
The	O
particular	O
subset	O
of	O
general	O
S-expressions	B-Protocol
applicable	O
here	O
is	O
composed	O
of	O
atoms	O
,	O
which	O
are	O
byte	O
strings	O
,	O
and	O
parentheses	O
used	O
to	O
delimit	O
lists	O
or	O
sub-lists	O
.	O
</s>
<s>
These	O
S-expressions	B-Protocol
are	O
fully	O
recursive	O
.	O
</s>
<s>
While	O
S-expressions	B-Protocol
are	O
typically	O
encoded	O
as	O
text	O
,	O
with	O
spaces	O
delimiting	O
atoms	O
and	O
quotation	O
marks	O
used	O
to	O
surround	O
atoms	O
that	O
contain	O
spaces	O
,	O
when	O
using	O
the	O
canonical	O
encoding	O
each	O
atom	B-Language
is	O
encoded	O
as	O
a	O
length-prefixed	O
byte	O
string	O
.	O
</s>
<s>
The	O
length	O
of	O
an	O
atom	B-Language
is	O
expressed	O
as	O
an	O
ASCII	B-Protocol
decimal	O
number	O
followed	O
by	O
a	O
"	O
:	O
"	O
.	O
</s>
<s>
No	O
quotation	O
marks	O
are	O
required	O
to	O
escape	O
the	O
space	O
character	O
internal	O
to	O
the	O
atom	B-Language
"	O
Canonical	O
S-expression	B-Protocol
"	O
,	O
because	O
the	O
length	O
prefix	O
clearly	O
points	O
to	O
the	O
end	O
of	O
the	O
atom	B-Language
.	O
</s>
<s>
There	O
is	O
no	O
whitespace	O
separating	O
an	O
atom	B-Language
from	O
the	O
next	O
element	O
in	O
the	O
list	O
.	O
</s>
<s>
Uniqueness	O
of	O
canonical	O
encoding	O
:	O
Forbidding	O
whitespace	O
between	O
list	O
elements	O
and	O
providing	O
just	O
one	O
way	O
of	O
encoding	O
atoms	O
ensures	O
that	O
every	O
S-expression	B-Protocol
has	O
exactly	O
one	O
encoded	O
form	O
.	O
</s>
<s>
Thus	O
,	O
we	O
can	O
decide	O
whether	O
two	O
S-expressions	B-Protocol
are	O
equivalent	O
by	O
comparing	O
their	O
encodings	O
.	O
</s>
<s>
So	O
,	O
a	O
cryptographic	O
hash	O
value	O
or	O
a	O
public	O
key	O
modulus	O
that	O
would	O
otherwise	O
have	O
to	O
be	O
encoded	O
in	O
base64	B-Protocol
or	O
some	O
other	O
printable	O
encoding	O
can	O
be	O
expressed	O
in	O
csexp	B-Protocol
as	O
its	O
binary	O
bytes	O
.	O
</s>
<s>
Support	O
for	O
type-tagging	O
encoded	O
information	O
:	O
A	O
csexp	B-Protocol
includes	O
a	O
non-S-expression	O
construct	O
for	O
indicating	O
the	O
encoding	O
of	O
a	O
string	O
,	O
when	O
that	O
encoding	O
is	O
not	O
obvious	O
.	O
</s>
<s>
Any	O
atom	B-Language
in	O
csexp	B-Protocol
can	O
be	O
prefixed	O
by	O
a	O
single	O
atom	B-Language
in	O
square	O
brackets	O
such	O
as	O
"[4:JPEG]"	O
or	O
"[24:text/plain;charset=utf-8]"	O
.	O
</s>
<s>
While	O
csexps	B-Protocol
generally	O
permit	O
empty	O
lists	O
,	O
empty	O
atoms	O
,	O
and	O
so	O
forth	O
,	O
certain	O
uses	O
of	O
csexps	B-Protocol
impose	O
additional	O
restrictions	O
.	O
</s>
<s>
For	O
example	O
,	O
csexps	B-Protocol
as	O
used	O
in	O
SPKI	O
have	O
one	O
limitation	O
compared	O
to	O
csexps	B-Protocol
in	O
general	O
:	O
every	O
list	O
must	O
start	O
with	O
an	O
atom	B-Language
,	O
and	O
therefore	O
there	O
can	O
be	O
no	O
empty	O
lists	O
.	O
</s>
<s>
Typically	O
,	O
a	O
list	O
's	O
first	O
atom	B-Language
is	O
treated	O
as	O
one	O
treats	O
an	O
element	O
name	O
in	O
XML	B-Protocol
.	O
</s>
<s>
JSON	B-General_Concept
(	O
and	O
YAML	B-Protocol
that	O
includes	O
"	O
JSON	B-General_Concept
as	O
an	O
official	O
subset	O
"	O
,	O
with	O
the	O
superset	O
,	O
meant	O
to	O
be	O
more	O
human-readable	B-General_Concept
.	O
)	O
</s>
<s>
Generally	O
,	O
csexp	B-Protocol
has	O
a	O
parser	O
one	O
or	O
two	O
decimal	O
orders	O
of	O
magnitude	O
smaller	O
than	O
that	O
of	O
either	O
XML	B-Protocol
or	O
ASN.1	B-Protocol
.	O
</s>
<s>
This	O
small	O
size	O
and	O
corresponding	O
speed	O
give	O
csexp	B-Protocol
its	O
main	O
advantage	O
.	O
</s>
<s>
csexp	B-Protocol
and	O
XML	B-Protocol
differ	O
in	O
that	O
csexp	B-Protocol
is	O
a	O
data-representation	O
format	O
,	O
while	O
XML	B-Protocol
includes	O
a	O
data-representation	O
format	O
and	O
also	O
a	O
schema	O
mechanism	O
.	O
</s>
<s>
Thus	O
,	O
XML	B-Protocol
can	O
be	O
"	O
configured	O
"	O
for	O
particular	O
kinds	O
of	O
data	O
,	O
which	O
conform	O
to	O
some	O
grammar	O
(	O
say	O
,	O
HTML	B-Language
,	O
ATOM	B-Language
,	O
SVG	B-Application
,	O
MathML	B-Language
,	O
or	O
new	O
ones	O
as	O
needed	O
)	O
.	O
</s>
<s>
It	O
has	O
languages	O
for	O
defining	O
document	O
grammars	O
:	O
DTD	B-Language
is	O
defined	O
by	O
the	O
XML	B-Protocol
standard	O
itself	O
,	O
while	O
XSD	O
,	O
RelaxNG	B-Language
,	O
and	O
Schematron	B-Language
are	O
commonly	O
used	O
with	O
XML	B-Protocol
for	O
additional	O
features	O
,	O
and	O
XML	B-Protocol
can	O
also	O
work	O
with	O
no	O
schema	O
.	O
</s>
<s>
csexp	B-Protocol
data	O
can	O
of	O
course	O
be	O
operated	O
on	O
by	O
schemas	O
implemented	O
at	O
a	O
higher	O
level	O
,	O
but	O
provides	O
no	O
such	O
mechanism	O
itself	O
.	O
</s>
<s>
In	O
terms	O
of	O
characters	O
and	O
bytes	O
,	O
a	O
csexp	B-Protocol
"	O
string	O
"	O
may	O
have	O
any	O
byte	O
sequence	O
whatsoever	O
(	O
because	O
of	O
the	O
length	O
prefix	O
on	O
each	O
atom	B-Language
)	O
,	O
while	O
XML	B-Protocol
(	O
like	O
regular	O
Lisp	B-Language
S-expressions	B-Protocol
,	O
JSON	B-General_Concept
,	O
and	O
literals	O
in	O
programming	O
languages	O
)	O
,	O
requires	O
alternate	O
representations	O
for	O
a	O
few	O
characters	O
(	O
such	O
as	O
"	O
<	O
"	O
and	O
most	O
control	O
characters	O
)	O
.	O
</s>
<s>
XML	B-Protocol
also	O
provides	O
mechanisms	O
to	O
specify	O
how	O
a	O
given	O
byte	O
sequence	O
is	O
intended	O
to	O
be	O
interpreted	O
:	O
Say	O
,	O
as	O
a	O
Unicode	O
UTF-8	O
string	O
,	O
a	O
JPEG	O
file	O
,	O
or	O
an	O
integer	O
;	O
csexp	B-Protocol
leaves	O
such	O
distinctions	O
to	O
external	O
mechanisms	O
.	O
</s>
<s>
At	O
the	O
most	O
basic	O
level	O
,	O
both	O
csexp	B-Protocol
and	O
XML	B-Protocol
represent	O
trees	O
(	O
as	O
do	O
most	O
other	O
external	O
representations	O
)	O
.	O
</s>
<s>
This	O
is	O
not	O
surprising	O
,	O
since	O
XML	B-Protocol
can	O
be	O
described	O
as	O
a	O
differently-punctuated	O
form	O
for	O
LISP-like	O
S-expressions	B-Protocol
,	O
or	O
vice	O
versa	O
.	O
</s>
<s>
However	O
,	O
XML	B-Protocol
includes	O
additional	O
semantics	O
,	O
which	O
are	O
commonly	O
achieved	O
in	O
csexp	B-Protocol
by	O
various	O
conventions	O
rather	O
than	O
as	O
part	O
of	O
the	O
language	O
.	O
</s>
<s>
First	O
,	O
every	O
XML	B-Protocol
element	O
has	O
a	O
name	O
(	O
csexp	B-Protocol
applications	O
commonly	O
use	O
the	O
first	O
child	O
of	O
each	O
expression	O
for	O
this	O
)	O
.	O
</s>
<s>
Second	O
,	O
XML	B-Protocol
provide	O
datatyping	O
,	O
firstly	O
via	O
the	O
schema	O
grammar	O
.	O
</s>
<s>
An	O
XML	B-Protocol
element	O
may	O
also	O
have	O
attributes	O
,	O
a	O
construct	O
that	O
csexp	B-Protocol
does	O
not	O
share	O
.	O
</s>
<s>
To	O
represent	O
XML	B-Protocol
data	O
in	O
csexp	B-Protocol
,	O
one	O
must	O
choose	O
a	O
representation	O
for	O
such	O
attributes	O
;	O
an	O
obvious	O
one	O
is	O
to	O
reserve	O
the	O
second	O
item	O
in	O
each	O
S-expression	B-Protocol
for	O
a	O
list	O
of	O
(	O
name	O
value	O
)	O
pairs	O
,	O
analogous	O
to	O
the	O
LISP	B-Language
association	B-Data_Structure
list	I-Data_Structure
.	O
</s>
<s>
The	O
XML	B-Protocol
ID	O
and	O
IDREF	O
attributes	O
have	O
no	O
equivalent	O
in	O
csexp	B-Protocol
,	O
but	O
can	O
be	O
easily	O
implemented	O
by	O
a	O
csexp	B-Protocol
application	O
program	O
.	O
</s>
<s>
Finally	O
,	O
an	O
XML	B-Protocol
element	O
may	O
contain	O
comments	O
and/or	O
processing	O
instructions	O
.	O
</s>
<s>
csexp	B-Protocol
has	O
no	O
specific	O
equivalents	O
,	O
but	O
they	O
are	O
trivial	O
to	O
represent	O
,	O
merely	O
by	O
reserving	O
a	O
name	O
for	O
each	O
.	O
</s>
<s>
For	O
example	O
,	O
naming	O
them	O
"	O
*	O
COM	O
"	O
and	O
"	O
*	O
PI	O
"	O
(	O
the	O
"	O
*	O
"	O
prevents	O
ever	O
colliding	O
with	O
XML	B-Protocol
element	O
type	O
names	O
)	O
:	O
</s>
<s>
Both	O
csexp	B-Protocol
and	O
XML	B-Protocol
are	O
fully	O
recursive	O
.	O
</s>
<s>
The	O
first	O
atom	B-Language
in	O
a	O
csexp	B-Protocol
list	O
,	O
by	O
convention	O
roughly	O
corresponds	O
to	O
an	O
XML	B-Protocol
element	O
type	O
name	O
in	O
identifying	O
the	O
"	O
type	O
"	O
of	O
the	O
list	O
.	O
</s>
<s>
However	O
,	O
in	O
csexp	B-Protocol
this	O
can	O
be	O
any	O
atom	B-Language
in	O
any	O
encoding	O
(	O
e.g.	O
,	O
a	O
JPEG	O
,	O
a	O
Unicode	O
string	O
,	O
a	O
WAV	O
file	O
,	O
…	O
)	O
,	O
while	O
XML	B-Protocol
element	O
names	O
are	O
identifiers	O
,	O
constrained	O
to	O
certain	O
characters	O
,	O
like	O
programming-language	O
identifiers	O
.	O
</s>
<s>
csexp	B-Protocol
's	O
method	O
is	O
obviously	O
more	O
general	O
;	O
on	O
the	O
other	O
hand	O
,	O
Identifying	O
what	O
encoding	O
such	O
an	O
item	O
is	O
in	O
,	O
and	O
thus	O
how	O
to	O
interpret	O
it	O
,	O
is	O
determined	O
only	O
by	O
a	O
particular	O
user	O
's	O
conventions	O
,	O
meaning	O
that	O
a	O
csexp	B-Protocol
application	O
must	O
build	O
such	O
conventions	O
for	O
itself	O
,	O
in	O
code	O
,	O
documentation	O
,	O
and	O
so	O
forth	O
.	O
</s>
<s>
Similarly	O
,	O
csexp	B-Protocol
atoms	O
are	O
binary	O
(	O
consisting	O
of	O
a	O
length	O
prefix	O
followed	O
by	O
totally	O
arbitrary	O
bytes	O
)	O
,	O
while	O
XML	B-Protocol
is	O
designed	O
to	O
be	O
human-readable	B-General_Concept
(	O
while	O
arguably	O
less	O
so	O
than	O
JSON	B-General_Concept
or	O
YAML	B-Protocol
)	O
so	O
arbitrary	O
bytes	O
in	O
XML	B-Protocol
must	O
be	O
encoded	O
somehow	O
(	O
for	O
example	O
,	O
a	O
bitmapped	O
image	O
can	O
be	O
included	O
using	O
base64	B-Protocol
)	O
.	O
</s>
<s>
This	O
means	O
that	O
storing	O
large	O
amounts	O
of	O
non-readable	O
information	O
in	O
uncompressed	O
XML	B-Protocol
takes	O
more	O
space	O
;	O
on	O
the	O
other	O
hand	O
,	O
it	O
will	O
survive	O
translation	O
between	O
alternate	O
character	B-General_Concept
sets	I-General_Concept
(	O
including	O
transmission	O
through	O
network	O
hosts	O
that	O
may	O
apply	O
differing	O
character	B-General_Concept
sets	I-General_Concept
,	O
line-end	O
conventions	O
,	O
etc	O
.	O
</s>
<s>
It	O
has	O
been	O
suggested	O
that	O
XML	B-Protocol
"	O
merges	O
"	O
a	O
sequence	O
of	O
strings	O
within	O
one	O
element	O
into	O
a	O
single	O
string	O
,	O
while	O
csexp	B-Protocol
allows	O
a	O
sequence	O
of	O
atoms	O
within	O
a	O
list	O
and	O
those	O
atoms	O
remain	O
separate	O
from	O
one	O
another	O
;	O
but	O
this	O
is	O
incorrect	O
.	O
</s>
<s>
Exactly	O
like	O
S-expressions	B-Protocol
and	O
csexp	B-Protocol
,	O
XML	B-Protocol
has	O
a	O
notion	O
of	O
a	O
"	O
sequence	O
of	O
strings	O
"	O
only	O
if	O
the	O
"	O
strings	O
"	O
are	O
separated	O
somehow	O
:	O
</s>
<s>
ASN.1	B-Protocol
is	O
a	O
popular	O
binary	O
encoding	O
form	O
.	O
</s>
<s>
To	O
parse	O
an	O
ASN.1	B-Protocol
structure	O
,	O
one	O
must	O
tell	O
the	O
parser	O
what	O
set	O
of	O
structures	O
one	O
is	O
expecting	O
and	O
the	O
parser	O
must	O
match	O
the	O
data	O
type	O
being	O
parsed	O
against	O
the	O
structure	O
options	O
.	O
</s>
<s>
This	O
adds	O
to	O
the	O
complexity	O
of	O
an	O
ASN.1	B-Protocol
parser	O
.	O
</s>
<s>
A	O
csexp	B-Protocol
structure	O
carries	O
some	O
indication	O
of	O
its	O
own	O
semantics	O
(	O
encoded	O
in	O
element	O
names	O
)	O
,	O
and	O
the	O
parser	O
for	O
a	O
csexp	B-Protocol
structure	O
does	O
not	O
care	O
what	O
structure	O
is	O
being	O
parsed	O
.	O
</s>
<s>
Once	O
a	O
wire-format	O
expression	O
has	O
been	O
parsed	O
into	O
an	O
internal	O
tree	O
form	O
(	O
similar	O
to	O
XML	B-Protocol
's	O
DOM	O
)	O
,	O
the	O
consumer	O
of	O
that	O
structure	O
can	O
examine	O
it	O
for	O
conformance	O
to	O
what	O
was	O
expected	O
.	O
</s>
<s>
An	O
XML	B-Protocol
document	I-Protocol
without	O
a	O
schema	O
works	O
just	O
like	O
csexp	B-Protocol
in	O
this	O
respect	O
,	O
while	O
an	O
XML	B-Protocol
document	I-Protocol
with	O
them	O
can	O
work	O
more	O
like	O
ASN.1	B-Protocol
.	O
</s>
