[Home] [By Thread] [By Date] [Recent Entries]
On Sat, 16 Jun 2001, ted.krawiec@c... wrote: > Hi. I'm new to this list and I don't know if this topic has already been > discussed. I didn't find anything in the archives. > > My questions is: if an element is declared as <!ELEMENT myelement (#PCDATA)>, > is "<myelement></myelement>" valid. Yes, perfectly. An element type declaration in a DTD for PCDATA declared content alone can only specify that the element type *may* contain text, not that it has to. To specify compulsory textual content you need to use a Schema, not a DTD. > It is clearly well-formed according to productions [39] (element), [43] > (content), and [14] (CharData), but there is a Validity Constraint: Element > Valid on production [39], which states "An element is valid if ... 3. The > declaration matches Mixed and the content consists of character data and child > elements whose types match names in the content model." > > Although production 14 say that CharData can be the empty set, That's it. Null content is still "content". It's just null :-) These specs are very literal-minded (in order to be amenable to description in terms that a machine can understand) so if a production reduces to a statement that can equate to the empty set, then that is exactly what it means. > it seems that > this Validity Constraint is saying that there needs to be actual character > data. Otherwise, why else would you have a Validity Constraint for empty > character data? Because SGML, on which XML is founded, has no way of expressing "must contain at least one character" in terms of declared character data content. An element type which is present in the file but contains nothing is quite OK . [Historical note: it has to be. Think of starting to write a book using a DTD in which a chapter must contain a title followed by at least one paragraph or other element type...a very common setup. To create your outline you want to set up the chapters and titles...you're going to have to insert an empty paragraph for each chapter. So null text content had to be permissible. (That's actually not the whole story but it'll do :-)] > Maybe I'm just not understanding the XML 1.0 spec. In fact the MSXML 3.0 parser > says that "<myelement></myelement>" is valid. So I should hope. ///Peter
|

Cart



