Element Declarations

To declare the syntax of an element in a DTD, you use the <!ELEMENT> element like this: <!ELEMENT NAME CONTENT_MODEL > . Here, NAME is the name of the element you're declaring; CONTENT_MODEL can be set to EMPTY or ANY , or it can hold mixed content (other elements as well as parsed character data) or child elements.

Here are a few element examplesnote the expressions starting with % and ending with ; . Those expressions are parameter entity references, much like general entity references, except that you use them in DTDs, not the body of the document (we'll see parameter entities in the next chapter):

 <!ELEMENT direction (left, right, top?)>  <!ELEMENT CHAPTER (INTRODUCTION, (P  QUOTE  NOTE)*, DIV*)> <!ELEMENT HR EMPTY> <!ELEMENT p (#PCDATA  I)* > <!ELEMENT %title; %content; > <!ELEMENT DOCUMENT ANY> 

We're going to see how to create <!ELEMENT> elements like these in this chapter and the next one. I'll start by declaring the root element of the example document for this chapter, ch02_01.xml:

 <?xml version = "1.0" standalone="yes"?>  <!DOCTYPE DOCUMENT [  <!ELEMENT DOCUMENT ANY>  ]> <DOCUMENT> </DOCUMENT> 

Note that I'm specifying a content model of ANY here; see the next topic for the details on this keyword.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net