3 november 2008cis 340 # 1 topics to define xml as a technology to place xml in the context of...

46
3 November 2008 CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Post on 19-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

3 November 2008 CIS 340# 1

Topics

• To define XML as a technology• To place XML in the context of system

architectures

Page 2: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

3 November 2008 CIS 340# 2

Steps to Use XML: Create XML vocabulary / structure• Define a hierarchical relationship among the

whole / parts

SymbolDescription

“Child element occurs...”

Sample

[ none ] Only once A book can have only 1 title

? Once or not at all

A book may or may not have a collection of chapters

* Any number of times

A “books” can be a collection of book(s)

+ At least once A “chapters” element must have at least 1 chapter

Page 3: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

book

title

books

book*

book

chapter?

title

author+

books

book*

appendices

appendix+

book

title

?

chapters

chapter+

Page 4: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

3 November 2008 CIS 340# 4

Steps to Use XML: Use XML-vocabulary on a web page

• See jw cd.css

Steps to Use XML: Build CSS stylesheet to control display

• See jazz.xml

• See jazz withxcss.xml

Steps to Use XML: Reference CSS stylesheet with web page

Page 5: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

XML Parsers• An XML processor (also called XML parser)

evaluates the document to make sure it conforms to all XML specifications for structure and syntax.

• XML parsers are strict. It is this rigidity built into XML that ensures XML code accepted by the parser will work the same everywhere.– Microsoft’s parser is called MSXML and is built

directly in IE versions 5.0 and above.– Netscape developed its own parser, called Mozilla,

which is built into version 6.0 and above.

Page 6: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Well-Formed and Valid XML Documents

• There are two categories of XML documents– Well-formed– Valid

• An XML document is well-formed if it contains no syntax errors and fulfills all of the specifications for XML code as defined by the W3C.

• An XML document is valid if it is well-formed and also satisfies the rules laid out in the DTD or schema attached to the document.

Page 7: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

The Document Creation Process

This figure shows the document creation process

Page 8: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

The Structure of an XML Document

• XML documents consist of three parts– The prolog– The document body– The epilog

• The prolog is optional and provides information about the document itself

• The document body contains the document’s content in a hierarchical tree structure.

• The epilog is also optional and contains any final comments or processing instructions.

Page 9: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

The Structure of an XML Document: The XML Declaration• The XML declaration is always the first line of code in an

XML document. It tells the processor what follows is written using XML. It can also provide any information about how the parser should interpret the code.

• The complete syntax is: <?xml version=“version number” encoding=“encoding

type” standalone=“yes | no” ?>

• A sample declaration might look like this: <?xml version=“1.0” encoding=“UTF-8” standalone=“yes” ?>

Page 10: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

The Structure of an XML Document: Inserting Comments

• Comments or miscellaneous statements go after the declaration. Comments may appear anywhere after the declaration.

• The syntax for comments is:

<!- - comment text - ->

• This is the same syntax for HTML comments

Page 11: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Elements and Attributes

• Elements are the basic building blocks of XML files.

• An open or empty element: contains no content <element_name/>• A closed element, has the following syntax:

<element _ name>Content</element _ name>

• Example: <Artist>Miles Davis</Artist>

Page 12: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Elements and Attributes

• Element names are case sensitive

• Elements can be nested, as follows:<CD>Kind of Blue

<TRACK>So What (3:22)</TRACK><TRACK>Blue in Green (5:37)</TRACK>

</CD>

Page 13: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Elements and Attributes

• XML Elements are extensible and they have relationships.

• Elements are related as parents and children.

• All elements must be nested within a single document or root element. There can be only one root element.

Page 14: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Elements and Attributes

• XML elements can have attributes.• Attributes often provide information that is not a

part of the data. In the example below, the file type is irrelevant to the data, but important to the software that wants to manipulate the element:<file type="gif">computer.gif</file>

• . Attributes are text strings and must be placed in single or double quotes. The syntax is:

<element_name attribute=“value”> … </element_name>

Page 15: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Elements and Attributes

prolog

{document elements

Page 16: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Character References

• Special characters, such as the symbol for the British pound, can be inserted into your XML document by using a character reference. The syntax is:

&#character;

Page 17: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Character References

• Character is a entity reference number or name from the ISO/IEC character set.

• Character references in XML are the same as in HTML.

Page 18: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Character References

This figure shows commonly used character reference numbers

Page 19: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Character References

character reference

Page 20: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Displaying an XML Document in a Web Browser

• XML documents can be opened in Internet Explorer or in Netscape Navigator.

• If there are no syntax errors. IE will display the document’s contents in an expandable/collapsible outline format including all markup tags.

• Netscape 7.1 will display like IE does.• Netscape 6.2 will display the contents but

neither the tags nor the nested elements.

Page 21: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures
Page 22: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures
Page 23: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Linking to a Style Sheet

• The easiest way to turn an XML document into a formatted document is to link the document to a style sheet.

• The XML document and the style sheet are combined by the XML processor to display a single formatted document.

Page 24: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Linking to a Style Sheet

There are two main style sheet languages used with XML:– Cascading Style Sheets (CSS) and Extensible

Style Sheets (XSL)

• CSS is supported by most browsers and is relatively easy to learn and use.

• XSL is more powerful, but not as easy to use as CSS.

Page 25: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Linking to a Style Sheet

• There are some important benefits to using style sheets:– By separating content from format, you

can concentrate on the appearance of the document

– Different style sheets can be applied to the same XML document

– Any style sheet changes will be automatically reflected in any Web page based upon the style sheet

Page 26: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Applying a Style to an Element

• To apply a style sheet to a document, use the following syntax:

selector {attribute1:value1; attribute2:value2; …}

• selector is an element (or set of elements) from the XML document.

• attribute and value are the style attributes and attribute values to be applied to the document.

Page 27: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Applying a Style to an Element

• For example:

ARTIST {color:red; font-weight:bold}

• will display the text of the ARTIST element in a red boldface type.

Page 28: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Creating Processing Instructions

• The link from the XML document to a style sheet is created using a processing statement.

• A processing instruction is a command that gives instructions to the XML parser.

Page 29: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Creating Processing Instructions

• For example:

<?xml-stylesheet type=“style” href=“sheet” ?>

• Style is the type of style sheet to access and sheet is the name and location of the style sheet.

Page 30: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Style Sheet

This figure shows the cascading style sheet stored in the JW.css file

Page 31: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Linking to the JW.css Style Sheet

This figure shows how to link the JW.css style sheet to the Jazz.xml file

processing instruction to access the JW.css style

sheet

Page 32: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

The Document Formatted with the Style Sheet

Page 33: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

XML DTD

• Document Type Definition or Schema• Defines rules for how data in the

document should be structured. • Force a document to follow a defined

structure• A DTD can be declared inline in your

XML document, or as an external reference.

Page 34: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Internal DOCTYPE declaration

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><!DOCTYPE SPECIALS [<!ELEMENT SPECIALS (TITLE,CD)><!ELEMENT TITLE (#PCDATA)><!ELEMENT CD (ARTIST, TRACK)><!ELEMENT CD (#PCDATA)><!ELEMENT ARTIST (#PCDATA)><!ELEMENT TRACK (#PCDATA)>]>

<SPECIALS><TITLE>MOnthly Specials at the Jazz Warehouse</TITLE>

<CD>Kind of Blue

Root element

DATA statements

Page 35: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

External DOCTYPE declaration

<?xml version="1.0"?>

<!DOCTYPE SPECIAL SYSTEM “special.dtd">

<SPECIALS>

<TITLE>Monthly Specials at the Jazz Warehouse</TITLE>

<CD>Kind of Blue

<ARTIST>Miles Davis</ARTIST>

<TRACK length="9:22">So what</TRACK>

<TRACK length="9:46">Freddie Freeloader</TRACK>

<TRACK length="5:37">Blue in Green</TRACK>

<TRACK length="11:33">All Blues</TRACK>

Page 36: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

a copy of the file “speical.dtd" containing the DTD:

<!ELEMENT SPECIALS (TITLE,CD)><!ELEMENT TITLE (#PCDATA)><!ELEMENT CD (ARTIST, TRACK)><!ELEMENT CD (#PCDATA)><!ELEMENT ARTIST (#PCDATA)><!ELEMENT TRACK (#PCDATA

Page 37: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

XML document 1

DTD internal subset

XML document 2

DTDexternal subset

XML document 3

DTD internal subset

DTD internal subset

Page 38: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Creating an XML document (XML Syntax)

• XML document must be well formed:– A root element is required.– Closing tags are required.– Elements must be properly nested.– Case matters.– Attribute values must be quoted.– Entity references must be declared in a DTD or a

schema.

Page 39: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

What’s Wrong

<?xml version=“1.0” ?><CD>Kind of Blue

<TRACK>So What (9:22)</TRACK><TRACK>Freddie Freeloader (9:46)</TRACK>

<TRACK>All Blues (11:33)</TRACK> <TRACK>Flamenco Sketches (9:26)</TRACK></CD><CD>Cookin’

<TRACK>My Funny Valentine (5:57) </TRACK> <TRACK> Blues by Five (9:53) </TRACK> <TRACK> Airegin (4:22) </TRACK></CD>

Page 40: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

• Parsed character data (PCDATA) is text parsed by a browser or parser.

• Unparsed character data (CDATA) is text not processed by the browser or parser.

Page 41: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

CDATA Sections

• A CDATA section is a large block of text the XML processor will interpret only as text.

• The syntax to create a CDATA section is:

<! [CDATA [Text Block

] ]>

Page 42: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

CDATA Sections

• In this example, a CDATA section stores several HTML tags within an element named HTMLCODE:

<HTMLCODE>

<![CDATA[ <h1>The Jazz Warehouse</h1> <h2>Your Online Store for Jazz Music</h2> ] ]> </HTMLCODE>

Page 43: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

CDATA Sections

This figure shows the revised Jazz.xml file

CDATA section

Page 44: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Displaying an XML Document in a Web Browser

• To display the Jazz.xml file in a Web browser:

1. Start the browser and open the Jazz.xml file located in the Tutorial.01/Tutorial folder of your Data Disk.

2. Click the minus (-) symbols.

3. Click the resulting plus (+) symbols.

Page 45: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

Displaying an XML Document in a Web Browser

This figure shows the revised Jazz.XML file as seen in Internet Explorer 6.0 and Netscape 6.2

Page 46: 3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures

A Sample of an XML assignment