Exercises

6.4 Create a DTD (products, dtd) for a retailer with the following specifications: The XML document that conforms to the DTD must contain a list of products and manufacturers. Each product should be represented by a product element and each manufacturer should be represented by a manufacturer element. Each manufacturer has a unique ID. Represent details like name, address, etc., as child elements of a manufacturer element. Each product has attributes such as product code (which is always unique), unit price, etc. Each product is classified into one of four categories: electronics, household, furniture and groceries. Each product should be related to a manufacturer described in the XML document and should be represented as an element. The product can have a model name and description as elements. [Hint: Relate products to manufacturers using the IDREF type attribute.]

6.5 Use the DTD shown in Fig. 6.16 to construct an XML document. Use the declared entities for the authors element. Validate your XML document against the DTD using Microsoft's XML Validator (or a similar validation program).

Fig. 6.16 DTD for a book database (part 1 of 2).

164 Document Type Definition (DTD)

7

<

ENTITY

8

9

<

ENTITY

10

11

<

ELEMENT

12

<

ATTLIST

13

14

<

ELEMENT

15

16

<

ELEMENT

17

18

<

ELEMENT

19

20

<

ELEMENT

21

<

ATTLIST

22

23

<

ELEMENT

24

<

ATTLIST

25

26

<

ELEMENT

27

28

<

ELEMENT

29

30

<

ELEMENT

31

32

<

ELEMENT

6.6 Write an XML document that declares an address book containing contacts. Each contact has a name and address. An address should contain attributes for street name, state and phone number. The attribute value for state should not contain spaces. For example, "New York" would invalidate the XML document. The attribute value for a phone number must contain hyphens and no spaces (e.g., 978-555-1212). Use entities for states names. [Hint, use NMTOKENs]

6.7 Write an XML document for the DTD created in Exercise 6.6 and validate it.

6.8 Write a DTD for an XML document that stores company profiles. Each company is represented by a company element. Profiles must contain a name element and a tour element. Element tour points to a .jpg image or to an HTML page that relates to the company. Element tour should specify the type of image or document to which it points. [Note, The type of image should be specified by a NOTATION type attribute.]. Also write an XML document and validate it against this DTD.

6.9 For the preceding exercise, write an internal subset of declarations that declare the type attribute as enumerated. Make corresponding changes in the XML document. Observe that the internal subset overrides the external subset when declarations collide.

6.10 Briefly describe each element type declaration:

a) <!ELEMENT name ( firstName, middleName?, lastName )>

c) <!ELEMENT discussion ( agenda, ( issues, solutions )* )>

+1 0

Post a comment