Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2003 Pearson Education, Inc. Slide 2-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 2-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 2-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 2-2 CHAPTER 2 A Closer Look at XML Documents

4 Copyright © 2003 Pearson Education, Inc. Slide 2-3 XML Syntax “Syntax” refers to the rules of a language Syntax is needed with any language so that the documents created with that language are consistent Programs that process documents expect the syntax rules to be followed, otherwise the document may not be interpreted correctly

5 Copyright © 2003 Pearson Education, Inc. Slide 2-4 Components of an XML Document XML Declaration Elements Attributes Entities Comments

6 Copyright © 2003 Pearson Education, Inc. Slide 2-5 Components: The XML Declaration The XML Declaration: Tells the processing program that the document is an XML document, along with other optional information The declaration is always the first line of an XML document Attributes that can be used in the Declaration: version encoding standalone Example:

7 Copyright © 2003 Pearson Education, Inc. Slide 2-6 Components: XML Elements Elements: Used to describe the data. Consist of: A start tag Content An end tag Example: Content The “root” element of a document is the outermost element, and contains all of the other elements in the document. There can be only one root element in a single document An element that does not contain any content is known as an “empty element”

8 Copyright © 2003 Pearson Education, Inc. Slide 2-7 Element Nesting The term “nesting” refers to the process of containing elements within other elements Terminology: Child elements – elements that are contained within other elements Parent elements – elements that contain other elements Sibling elements – elements that share the same parent element

9 Copyright © 2003 Pearson Education, Inc. Slide 2-8 Nesting Example 1 2 Sally 3 Joe 4 5 Larry 6 Curly 7 Mo 8 9

10 Copyright © 2003 Pearson Education, Inc. Slide 2-9 Components: XML Attributes Attributes help to describe XML elements Attributes are always contained in the start tag of the element they are describing Attributes are known as “name-value pairs” Example: address=“123 Main Street”

11 Copyright © 2003 Pearson Education, Inc. Slide 2-10 Components: XML Entities Two types of entities: General – placeholders for information contained in the XML document Parameter – used within a DTD to reference a grouping of elements Three types of general entities: Character – used in place of special characters Content – used for blocks of frequently used text Unparsed – used for binary or non-text data, like image files

12 Copyright © 2003 Pearson Education, Inc. Slide 2-11 Examples of Entities Character entity: Character: > Entity reference: > or > Usage: x > y Content entity: Declaration: Usage: &address; Unparsed entity: Declaration: Usage: &aimage;

13 Copyright © 2003 Pearson Education, Inc. Slide 2-12 Components: Comments An XML comment is ignored by applications that process XML Comments are commonly used for documentation, or to add information for others viewing the document The content of the comment is surrounded by special comment tags: Example:

14 Copyright © 2003 Pearson Education, Inc. Slide 2-13 Well-Formed XML Documents A “well-formed” document is one which adheres to the syntax rules for XML: An XML document contains one root element All elements must have start and end tags, except for empty elements Elements must be properly nested All attributes must have a value Attributes can only appear in the start tag and must be unique to that element Element names are case-sensitive Special characters must be written as entities Names of element can start only with letters or an underscore, and can contain letters, numbers, hyphens, periods and underscores

15 Copyright © 2003 Pearson Education, Inc. Slide 2-14 XML Parsers A “parser” is a program that checks the syntax of an XML document to ensure that the document is well-formed Two types of parsers: Non-validating – only checks for syntax Validating – checks syntax and verifies the document against a DTD or Schema


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

Similar presentations


Ads by Google