Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide.

Similar presentations


Presentation on theme: "Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide."— Presentation transcript:

1

2 Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide to XML by Cheryl M. Hughes

3 Copyright © 2003 Pearson Education, Inc. Slide 3-2 CHAPTER 3 Describing XML Documents with DTD’s and XML Schemas

4 Copyright © 2003 Pearson Education, Inc. Slide 3-3 XML Document Model A “document model” is used to enforce structure within a document Two types of document models for XML: DTD – Document Type Definition XML Schema Document models are not required in XML

5 Copyright © 2003 Pearson Education, Inc. Slide 3-4 Validating Parsers A validating parser will check an XML document’s structure against a DTD or XML Schema Documents that conform to a document model are “valid” Validating parsers will report an error if the document does not conform to it’s document model, even if it is well-formed

6 Copyright © 2003 Pearson Education, Inc. Slide 3-5 Document Type Definition (DTD) XML elements and attributes are defined in a DTD DTD’s are “extensible” – meaning that they can be extended to meet the needs of the task at hand Two types of DTD’s: Internal – DTD exists as part of the document External – DTD is an external file Many free public DTD’s exist today, and can be downloaded from the Internet

7 Copyright © 2003 Pearson Education, Inc. Slide 3-6 DTD Declarations Element declaration: Attribute declaration: <!ATTLIST element_name attribute_name-1datatype default_value attribute_name-2datatype default_value attribute_name-3datatype default_value>

8 Copyright © 2003 Pearson Education, Inc. Slide 3-7 Elements: Content Model Types Text: Description: text or character data Syntax: (#PCDATA) Elements: Description: contains other elements Syntax: (element_1, element_2, …) Mixed Content: Description: contains both text and other elements Syntax: (#PCDATA, element_1, element_2, …) Empty: Description: does not contain any content Syntax: EMPTY Any: Description: can contain text or elements Syntax: ANY

9 Copyright © 2003 Pearson Education, Inc. Slide 3-8 Elements: Character Notations Question Mark: Character: ? Description: element may occur zero or one time Usage: email? Asterisk: Character: * Description: element may occur zero or more times Usage: email* Plus: Character: + Description: element may occur one or many times Usage: email+

10 Copyright © 2003 Pearson Education, Inc. Slide 3-9 Elements: Character Notations (cont.) Parentheses: Character: ( ) Description: used to indicate a set Usage: (name, address, zip_code) Vertical bar: Character: | Description: used to indicate a set of values Usage: a | b | c Comma: Character:, Description: used to indicate element sequence Usage: (a, b, c)

11 Copyright © 2003 Pearson Education, Inc. Slide 3-10 Attributes: Default Values Attribute type: #FIXED Description: value of the attribute must match the value assigned in the DTD Attribute type: #REQUIRED Description: element must contain the attribute to be valid Attribute type: #IMPLIED Description: attribute it optional

12 Copyright © 2003 Pearson Education, Inc. Slide 3-11 Attributes: A Few Data Types Data type: CDATA Description: character data Data type: ID Description: unique identifier to give an element a label Data type: Enumerated List (ie – (a, b, c) ) Description: list of all possible values that the attribute can contain

13 Copyright © 2003 Pearson Education, Inc. Slide 3-12 DTD Example: XML File 1 2 3<message num=”a1” to=”joe@acmeshipping.com” 4from=”brenda@xyzcompany.com” date=”02/09/01”> 5 6 7Joe, 8Please let me know if order number 10011 has shipped. 9Thanks, 10Brenda 11 12 13 14

14 Copyright © 2003 Pearson Education, Inc. Slide 3-13 DTD Example: Internal DTD 1 <!DOCTYPE emails [ 2 3 4 <!ATTLIST message 5numID#REQUIRED 6toCDATA#REQUIRED 7from CDATA#FIXED“brenda@xyzcompany.com” 8dateCDATA#REQUIRED> 9 10<!ATTLIST subject 11titleCDATA#IMPLIED> 12 13 14<!ATTLIST reply 15status (yes | no) "no"> 16 ]>

15 Copyright © 2003 Pearson Education, Inc. Slide 3-14 DTD Example: Document with DTD 1 2 <!DOCTYPE emails [ 3 4 5 <!ATTLIST message 6numID#REQUIRED 7toCDATA#REQUIRED 8from CDATA#FIXED “brenda@xyzcompany.com” 9dateCDATA#REQUIRED> 10 11<!ATTLIST subject 12titleCDATA#IMPLIED> 13 14 15<!ATTLIST reply 16status (yes | no)"no"> 17 ]> 18

16 Copyright © 2003 Pearson Education, Inc. Slide 3-15 DTD Example: Document with DTD (cont.) 19 20<message num=”a1” to=”joe@acmeshipping.com” 21from=”brenda@xyzcompany.com” date=”02/09/01”> 22 23 24Joe, 25Please let me know if order number 10011 has shipped. 26Thanks, 27Brenda 28 29 30 31

17 Copyright © 2003 Pearson Education, Inc. Slide 3-16 External DTD External DTD’s are defined in files that are external to the XML document XML Declaration for external DTD: DTD Declaration for external DTD:

18 Copyright © 2003 Pearson Education, Inc. Slide 3-17 XML Schema Overview XML Schema specification released by the W3C in May 2001, and contains two parts: Part I - structure Part II - data types Developed as an alternative to DTD’s and is much more powerful Features: Pattern matching Rich set of data types Attribute grouping Supports XML namespaces Follows XML syntax


Download ppt "Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide."

Similar presentations


Ads by Google