Embedding Content as Element Content or As An Attribute Value

Chris Maden crism at ora.com
Thu Jan 8 22:08:08 GMT 1998

[Tyler Baker]
> After getting used to the syntax of XML for defining a DTD, I am a
> little perplexed about an element declaration of the form:
> <!ELEMENT Foo (bar1 | bar2 | bar3)*>
> vs.
> <!ELEMENT Foo (bar1, bar2, bar3)*>
> Apparently in the first example element Foo can have 0 or more bar1,
> bar2, or bar3 attributes but only one of these, excluding the other,
> and the second example element says that you have 0 or more
> sequences of bar1, bar2, and bar3 attributes.  My confusion is that
> in the DTD's I have seen so far, the first example element is used
> as if attributes bar1, bar2, and bar3 can all exist together or else
> as a combination of two, or else singularly.  But in EBNF notation
> the ' | ' as far as I know means one or the other and not both.

You are confused about many things.  The | in EBNF means what you
think.  DTDs are not EBNF (note the lack of '::=').  The first example
means zero or more of (bar1 | bar2 | bar3) - each of that "zero or
more" must be only one of those, but there is no restriction that it
be the same bar every time.  The model you describe would be (bar1* |
bar2* | bar3*).

> <!ELEMENT Foo (bar1?, bar2?, bar3?)>
> Last but not least this example element seems to mean the same thing
> as the second example element.

The asterisk in (bar1, bar2, bar3)* means zero or more sequences of
bar1, bar2, bar3.  The third element declaration's (bar1?, bar2?,
bar3?), means an optional bar1 (zero or one), followed by an optional
bar2, followed by an optional bar3.  There may not be another bar1
after bar3, as there may be in the second element declaration.

> I am sorry to be posting this "please help me" post to an xml-dev
> list (which I assume is mostly for parser writing discussion), but I
> have tried in the short time I have been on this list I have tried
> to post pointers to parser writers that help them in their quest for
> optimal importance so I don't feel too guilty (-:

The best place for questions like this is probably comp.text.sgml.  I
also recommend _Practical SGML_ by Erik van Herwijnen, Kluwer
Academic, ISBN 0792394348.  Of the XML books thus far published,
_Presenting XML_ has some discussion of content models that hasn't
been obsoleted; _XML Complete_ has some discussion if you can pick
amongst the Java programming examples that comprise most of the book.

> Any info on this would be greatly appreciated as I cannot find any
> FAQ which explains this in detail other than the current XML spec
> which IMHO has a lot of ambiguities that are not clearly explained
> and therefore relatively confusing to anyone who does not have
> extensive experience in the SGML camp.

<URL:http://www.ucc.ie/xml/> is the XML FAQ, maintained by Peter
Flynn.  Ambiguities should probably be pointed out to the editors.
There are few or no ambiguities in the Platonic spec, in the heads of
the Working Group, but that Platonic ideal is not captured perfectly
in the published spec.

<!ENTITY crism PUBLIC "-//O'Reilly//NONSGML Christopher R. Maden//EN"
"<URL>http://www.oreilly.com/people/staff/crism/ <TEL>+1.617.499.7487
<USMAIL>90 Sherman Street, Cambridge, MA 02140 USA" NDATA SGML.Geek>

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

More information about the Xml-dev mailing list