Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Root element specified by DTD ? >Thread Next - Re: Root element specified by DTD ? Re: Root element specified by DTD ?To: NULL Date: 6/3/2006 12:27:00 AM Andy Dingley <dingbat@c...> wrote: > What specifies the permitted root element(s) for a document ? HTML, > SGML, XHTML or XML ? When using a DTD, any declared element type can be the root element. It must be specified in the Document Type Declaration in the XML file. The same is true for SGML, HTML, XHTML eg <!DOCTYPE table PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"> specifies a document starting with <table> and containing anything valid in HTML 4.01 tables. Warning: *browsers* are not SGML conforming applications, so they won't understand this. They *will* understand if you use XML or XHTML, but I don't know what their reaction to a XHTML fragment would be. > My question is, is there any way to author a non-HTML DTD (SGML or XML) > so as to restrict valid documents to only allow a certain subset of > their elements to be used as the root element? Yep, just use the element type name of your choice in the Document Type Declaration. This is required to be supported by all conforming editors using a DTD. If you use a Schema, all bets are off, as the specification of a root element type is done quite differently there. > Can this restriction be > expressed _entirely_ within a DTD? No, not at all. *Any* element type of a DTD can be used as the root element type. But conforming applications (eg editors) usually make a good guess if they are worth anything, when they parse the DTD -- it's not hard for them to spot that at least one element type is never used in the content model of any other element type, and is therefore a good choice for a default root element type. Oddly, some otherwise very good editors fail to do this, possibly because their programmers simply didn't grok XML markup. > Is this used within the HTML DTDs ? > (i.e. not just in the doctypedecl) Not explicitly. > Is this fragment a valid HTML document ? Yes, perfectly. > If not, why isn't it? Just > which part of its definition is forbidding this fragmentary use? > <!DOCTYPE div PUBLIC "-//W3C//DTD HTML 4.01//EN" > "http://www.w3.org/TR/html4/strict.dtd"> > <div> > <p>Foo</p> > </div> You can test this by running it through any SGML validating parser (eg nsgmls). > Good tutorial refs on DTDs are also welcome. I don't know anything like > enough on DTD innards. The best by far is still Eve Maler and Jeanne El Andaloussi, "Developing SGML DTDs -- from text to model to markup", Prentice Hall, 1996. You just have to skip the bits which refer to those parts of SGML which were dropped in the XML Specification (see the list in the FAQ on converting DTDs to XML at http://xml.silmaril.ie/developers/dtdconv/). But you should also bone up on Relax NG, which is a schema language with a short (DTD-like) syntax as well as a verbose syntax, from which you can generate DTDs, W3C Schemas, and more. This may be an easier way into document modelling. ///Peter -- XML FAQ: http://xml.silmaril.ie/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
