Document Type Definition(DTD) The type of an XML document can be specified using a DTD DTD constraints structure of XML data What elements can occur What attributes can/must an element have What subelements can/must occur inside each element,and how many times. DTD does not constrain data types All values represented as strings in XML DTD syntax <!ELEMENT element(subelements-specification)> <!ATTLIST element(attributes)> Database System Concepts-5th Edition,Aug 22,2005. 10.17 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.17 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. Document Type Definition (DTD) The type of an XML document can be specified using a DTD DTD constraints structure of XML data What elements can occur What attributes can/must an element have What subelements can/must occur inside each element, and how many times. DTD does not constrain data types All values represented as strings in XML DTD syntax <!ELEMENT element (subelements-specification) > <!ATTLIST element (attributes) >
Element Specification in DTD Subelements can be specified as names of elements,or #PCDATA(parsed character data),i.e.,character strings EMPTY(no subelements)or ANY(anything can be a subelement) Example <ELEMENT depositor(customer name account_number)> <ELEMENT customer_name (#PCDATA)> <ELEMENT account number (#PCDATA)> Subelement specification may have regular expressions <!ELEMENT bank (account customer depositor)+)> Notation: -“"-alternatives “+”-1 or more occurrences -“*”-0 or more occurrences Database System Concepts-5th Edition,Aug 22,2005. 10.18 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.18 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. Element Specification in DTD Subelements can be specified as names of elements, or #PCDATA (parsed character data), i.e., character strings EMPTY (no subelements) or ANY (anything can be a subelement) Example <! ELEMENT depositor (customer_name account_number)> <! ELEMENT customer_name (#PCDATA)> <! ELEMENT account_number (#PCDATA)> Subelement specification may have regular expressions <!ELEMENT bank ( ( account | customer | depositor)+)> Notation: – “|” - alternatives – “+” - 1 or more occurrences – “*” - 0 or more occurrences
Bank DTD <!DOCTYPE bank <!ELEMENT bank (account customer depositor)+)> <!ELEMENT account(account number branch_name balance)> <ELEMENT customer(customer name customer_street customer_city)> < ELEMENT depositor(customer name account_number)> <ELEMENT account_number(#PCDATA)> <ELEMENT branch name(#PCDATA)> <ELEMENT balance(#PCDATA)> <ELEMENT customer_name(#PCDATA)> <ELEMENT customer street(#PCDATA)> <ELEMENT customer city(#PCDATA)> ]> Database System Concepts-5th Edition,Aug 22,2005. 10.19 @Silberschatz,Korth and Sudarshan
Database System Concepts - 5 10.19 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. Bank DTD <!DOCTYPE bank [ <!ELEMENT bank ( ( account | customer | depositor)+)> <!ELEMENT account (account_number branch_name balance)> <! ELEMENT customer(customer_name customer_street customer_city)> <! ELEMENT depositor (customer_name account_number)> <! ELEMENT account_number (#PCDATA)> <! ELEMENT branch_name (#PCDATA)> <! ELEMENT balance(#PCDATA)> <! ELEMENT customer_name(#PCDATA)> <! ELEMENT customer_street(#PCDATA)> <! ELEMENT customer_city(#PCDATA)> ]>
Attribute Specification in DTD Attribute specification for each attribute Name Type of attribute CDATA ID(identifier)or IDREF (ID reference)or IDREFS (multiple IDREFs) more on this later Whether mandatory (#REQUIRED) has a default value (value), >or neither (#IMPLIED) Examples <!ATTLIST account acct-type CDATA "checking"> <!ATTLIST customer customer idID REQUIRED accounts IDREFS#REQUIRED > Database System Concepts-5th Edition,Aug 22,2005. 10.20 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.20 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. Attribute Specification in DTD Attribute specification : for each attribute Name Type of attribute CDATA ID (identifier) or IDREF (ID reference) or IDREFS (multiple IDREFs) – more on this later Whether mandatory (#REQUIRED) has a default value (value), or neither (#IMPLIED) Examples <!ATTLIST account acct-type CDATA “checking”> <!ATTLIST customer customer_id ID # REQUIRED accounts IDREFS # REQUIRED >
IDs and IDREFs An element can have at most one attribute of type Id The ID attribute value of each element in an XML document must be distinct Thus the ID attribute value is an object identifier An attribute of type IDREF must contain the ID value of an element in the same document An attribute of type IDREFS contains a set of(0 or more)ID values. Each Id value must contain the Id value of an element in the same document Database System Concepts-5th Edition,Aug 22,2005. 10.21 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.21 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. IDs and IDREFs An element can have at most one attribute of type ID The ID attribute value of each element in an XML document must be distinct Thus the ID attribute value is an object identifier An attribute of type IDREF must contain the ID value of an element in the same document An attribute of type IDREFS contains a set of (0 or more) ID values. Each ID value must contain the ID value of an element in the same document