Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example Write the DTD rules for the following XML fragment. Kim 34 South Street NY USA Vice President $175,000 1.

Similar presentations


Presentation on theme: "Example Write the DTD rules for the following XML fragment. Kim 34 South Street NY USA Vice President $175,000 1."— Presentation transcript:

1 Example Write the DTD rules for the following XML fragment. Kim 34 South Street NY USA Vice President $175,000 1

2 Example The rules must satisfy the following constraints: Each employee must have a single name. An employee must have at least one address. For the address, specifying the street is optional. The address must include the state and country information. The address can also include a phone number element. Each employee can specify zero or more phone numbers. Each employee must have a job title and a salary. 2

3 DTD – Declaring Attributes An attribute declaration has the following syntax: XML example: DTD example: The attribute’s attribute-type value is usually set to CDATA (Character DATA). 3

4 DTD – Declaring Attributes The default-value can be one of the following:  Value : default value of the attribute  #REQUIRED: the attribute is required  #IMPLIED: the attribute is implied  #FIXED value: the attribute value is fixed 4

5 DTD – Declaring Attributes (Default Attribute Value) In the following example, the "square" element is defined to be an empty element with a "width" attribute of type CDATA. If no width is specified, it has a default value of 0. DTD: Valid XML: 5

6 DTD – Declaring Attributes (#REQUIRED Attribute Value) The #REQUIRED keyword is used if there is not an option for a default value, but still want to force the attribute to be present. DTD: Valid XML: Invalid XML: 6

7 DTD – Declaring Attributes (#IMPLIED Attribute Value) The #IMPLIED keyword is used if we don't want to force the author to include an attribute, and you don't have an option for a default value. DTD: Valid XML: Valid XML: 7

8 DTD – Declaring Attributes (#FIXED Attribute Value) The #FIXED keyword is used to make the attribute value fixed. When using fixed the author can not change the attribute value. If an author includes another value, the XML parser will return an error. DTD: Valid XML: Invalid XML: 8

9 XML Fragment Mathew XML Guide 44.95 Assume that each book must have an id The defualt currency is USD. 9

10 Corresponding DTD 10

11 Referencing DTD files In the XML file, the DOCTYPE declaration is used to reference an external DTD file. It allows the validator to determine the corresponding DTD used in the validation process. Syntax: XML file: … 11

12 Example Write the corresponding DTD for the following XML fragment. Fatma ISC AAD Sarah FSC 12

13 Example The rules must satisfy the following constraints: Student List must contain at least one student. Each Student must have a major. Students can have multiple minors. Student ids are required for each student. The default college for the list of students is CFW. Specifying students gpa is optional. 13


Download ppt "Example Write the DTD rules for the following XML fragment. Kim 34 South Street NY USA Vice President $175,000 1."

Similar presentations


Ads by Google