Why must an XML document contain an element?

Tim Bray tbray at textuality.com
Tue May 6 20:47:39 BST 1997

At 02:19 PM 5/6/97 -0400, Eric Baatz - Sun Microsystems Labs BOS wrote:

>  [23] document ::= Prolog element Misc*
>So I could force the client to send:
>  <?XML version="1.0" encoding="UCS-2"?>
>  <foobar/>
>  This is plain text.

This would still not work, because "This is plain text." doesn't
match the nonterminal 'Misc'.  You need:

<foobar>This is plain text.</foobar>

>But forcing the inclusion of characters that don't convey any
>useful information to the application goes against my sense of
>Why must an XML document include at least one element?

If you don't have any useful info to convey, then don't put in
the tag.  It's not XML, but the text is presumably still useful.

It is a defining characteristic of XML that any "character data", 
i.e. non-markup text, has to be part of an element.  In other words,
a document must have a logical structure, and all its text must
have a place in that logical structure.  One benefit: you know
unambiguously when the message has ended, without waiting for
sockets to close and so on.  One of the things that makes XML
processors simple is they can look simple-mindedly for begin and
end tags, no exceptions.

I can accept that there are tons of useful documents that do not
have an explicitly-marked up logical structure, and an important
place in the world for plain text.  And, we hope, an important 
place for XML.  But they're not the same thing. -Tim

xml-dev: A list for W3C XML Developers
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To unsubscribe, send to majordomo at ic.ac.uk the following message;
unsubscribe xml-dev
List coordinator, Henry Rzepa (rzepa at ic.ac.uk)

More information about the Xml-dev mailing list