Example:Element Description A name is an optional title (e.g., "Prof."),a first name,and a last name, in that order,or it is an IP address: KIELEMENT NAME (TITLE?,FIRST LAST)IPADDR 16
16 Example: Element Description A name is an optional title (e.g., “Prof.”), a first name, and a last name, in that order, or it is an IP address: <!ELEMENT NAME ( (TITLE?, FIRST, LAST) | IPADDR )>
Use of DTD's 1.Set standalone ="no". 2.Either: a)Include the DTD as a preamble of the XML document,or b)Follow DOCTYPE and the <root tag>by SYSTEM and a path to the file where the DTD can be found. 17
17 Use of DTD’s 1. Set standalone = “no”. 2. Either: a) Include the DTD as a preamble of the XML document, or b) Follow DOCTYPE and the <root tag> by SYSTEM and a path to the file where the DTD can be found
Example:(a) <?xml version =1.0%standalone =no"?> K!DOCTYPE BARS <!ELEMENT BARS (BAR*)> <!ELEMENT BAR (NAME,BEER+)> The DTD <!ELEMENT NAME (#PCDATA)> <IELEMENT BEER (NAME,PRICE) <IELEMENT PRICE (#PCDATA)> The document <BARS> <BAR><NAME>Joe's Bar</NAME> <BEER><NAME>Bud</NAME><PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME><PRICE>3.00</PRICE></BEER> </BAR> <BAR>... </BARS> 18
18 Example: (a) <?xml version = “1.0” standalone = “no” ?> <!DOCTYPE BARS [ <!ELEMENT BARS (BAR*)> <!ELEMENT BAR (NAME, BEER+)> <!ELEMENT NAME (#PCDATA)> <!ELEMENT BEER (NAME, PRICE)> <!ELEMENT PRICE (#PCDATA)> ]> <BARS> <BAR><NAME>Joe’s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR> … </BARS> The DTD The document
Example:(b) Assume the BARS DTD is in file bar.dtd. <?xml version ="1.0"standalone ="no"?> <DOCTYPE BARS SYSTEM "bar.dtd" <BARS> Get the DTD <BAR><NAME>Joe's Bar</NAME> from the file <BEER><NAME>Bud</NAME> bar.dtd <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR>... </BARS> 19
19 Example: (b) Assume the BARS DTD is in file bar.dtd. <?xml version = “1.0” standalone = “no” ?> <!DOCTYPE BARS SYSTEM ”bar.dtd”> <BARS> <BAR><NAME>Joe’s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR> … </BARS> Get the DTD from the file bar.dtd
Attributes Opening tags in XML can have attributes. ▣In a DTD, <IATTLIST E...> declares attributes for element E, along with its datatype. The declaration of the form: <!ATTLIST element-name,attribute-name,type> 20
20 Attributes Opening tags in XML can have attributes. In a DTD, <!ATTLIST E . . . > declares attributes for element E, along with its datatype. The declaration of the form: <!ATTLIST element-name, attribute-name, type>