28
Thayer School of Engineering Dartmouth Lecture 2 Overview Web Services concept XML introduction Visual Studio .net

Lecture 2 Overview

  • Upload
    lesley

  • View
    45

  • Download
    0

Embed Size (px)

DESCRIPTION

Lecture 2 Overview. Web Services concept XML introduction Visual Studio .net. HTML Primer. HTML is HyperTex Markup Language HTML is a “specialization” of SGML HTML is a language for describing how web pages should look. HTML has some constructions for - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Lecture 2 Overview

• Web Services concept• XML introduction• Visual Studio .net

Page 2: Lecture 2 Overview

Thayer School of EngineeringDartmouth

HTML is HyperTex Markup Language

HTML is a “specialization” of SGML

HTML is a language for describing how web pagesshould look. HTML has some constructions forforms, frames, etc that make it a bit more dynamic.

HTML is very simple....we’re going to go overonly the basics...other sources:

- read the source of other pages- web HTML manuals and how-to’s

HTML Primer

Page 3: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Basic syntax of an HTML• HTML uses “tags”• tags typically have a beginning and a closing

version.• example....every html page should start with the tag

– <html>

and end with

– </html>

Not essential but good style.

Page 4: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Basic structure of an HTML page

<html><head><title>Our first page!!</title></head><body>Blah, blah, blah</body></html>

Page 5: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Why Web Services?• HTML describes the formatting of a web

page • Originally designed to let people read web

pages easily via that formatting• The structure of the page is not necessarily

conveyed by HTML• The meaning of a page is certainly not in the

HTML• If programs are to consume information on

web pages, then HTML is not enough

Page 6: Lecture 2 Overview

Thayer School of EngineeringDartmouth

What are Web Services?

• A language to define web resources’ structure/syntax - XML

• A transport protocol for moving XML - SOAP

• A language to describe a service – WSDL

• Directory-like services to locate XML described services - UDDI

Page 7: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Example of XML

<priceList>   <coffee>     

<name>Mocha Java</name>     <price>11.95</price>   

</coffee>   <coffee>     

<name>Sumatra</name>     <price>12.50</price>   

</coffee> </priceList>

Page 8: Lecture 2 Overview

Thayer School of EngineeringDartmouth

XML Overview

• XML vs HTML– HTML is a presentation markup language– XML is a content markup language– both are derivatives of SGML– “elements”, “attributes”, “values” and content– syntax is more strict in XML than in HTML– large development activity underway– version 1.0

Page 9: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Examples

• DARPA Agent Markup Language (DAML)• Genome information• XML registries• MathML

Page 10: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Example

Created with a text editor and saved in file.xml

<?xml version="1.0"?>

<contact-info><name format=“FNLN”>Jane Smith</name><company>AT&amp;T</company><phone>(212) 555-4567</phone></contact-info>

Page 11: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Example

<name format=“FNLN”>Jane Smith</name>

element attribute value content

Elements can be nested interspersed with “text”

<people><name format=“FNLN”>Jane Smith</name>worksat <company>AT&amp;T</company>.</people>

Page 12: Lecture 2 Overview

Thayer School of EngineeringDartmouth

XML Declaration

All XML documents can optionally begin with an XML declaration. The XML declaration provides at a minimum the number of the version of XML in use:

<?xml version="1.0"?>

Currently, 1.0 is the only approved version of XML, but others may appear in the future.

The XML declaration can also specify the character encoding used in the document:

<?xml version="1.0" encoding="UTF-8"?>

Page 13: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Encodings

All XML parsers: Unicode “UTF-8” and “UTF-16” encodings.

the XML declaration is case sensitive: it may not begin with “<?XML” or any other variant;

if the XML declaration appears at all, it must be the very first thing in the XML document: not even whitespace or comments may appear before it; and

it is legal for a transfer protocol like HTTP to override the encoding value that you put in the XML declaration, so you cannot guarantee that the document will actually use the encoding provided in the XML declaration.

Page 14: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Elements

“elements” are the logical units of information in an XML document.

An element consists of a start tag, optional text or other complete elements, followed by an end tag.

<p><person>Tony Blair</person> is <function>Prime Minister</function> of <location><country>GreatBritain</country></location></p>.

Page 15: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Parsing this example...

the p element, that contains the entire example (the person element, the text “ is ”, the function element, the text “ of ”, and the location element);

the person element, that contains the text “Tony Blair”;

the function element, that contains the text “Prime Minister”;

the location element, that contains the country element; and

the country element, that contains the text “Great Britain”.

Page 16: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Element “tree”

Page 17: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Syntax errors

<!-- WRONG! --><function><person>President</function>

Habibe</person>

Tags must be nested properly. eg...

<!-- RIGHT--><person><function>President</function> Habibe</person>

Page 18: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Syntax....

An XML document must have only one “root” element.

<!-- WRONG! --><a>...</a><b>...</b>

The following example fixes the problem by including both the a and b elements within a new x root element:

<x><a>...</a><b>...</b></x>

Page 19: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Syntax....<!-- WRONG! --><a href="pbear.html">polar bear</A>

This example will cause a parser error because an XML processor considers a and A to be separate elements, so the start and end tags do not match. Case sensitive!!!

XML has a special empty-element tag that represents both the start tag and the end tag:

<p>Stuff<hr/>More stuff.</p>

In this example, “<hr/>” represents both the start and the end of the hr element; equivalent to “<hr></hr>”

Page 20: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Attributes

In addition to marking the beginning of an element, XML start tags also provide a place to specify attributes. An attribute specifies a single property for an element, using a name/value pair. One very well known example of an attribute is href in HTML:

<a href="http://www.yahoo.com/">Yahoo!</a>

In this example, the content of the a element is the text “Yahoo!”; the attribute href provides extra information about the element (in this case, the Web page to load when a user selects the link).

Page 21: Lecture 2 Overview

Thayer School of EngineeringDartmouth

AttributesEvery attribute assignment consists of two parts: the attribute name (for example, href), and the attribute value (for example, http://www.yahoo.com/). Some rules :

Attribute names in XML (unlike HTML) are case sensitive: HREF and href refer to two different XML attributes.

You may not provide two values for the same attribute in the same start tag. This is wrong:<!-- WRONG! --> <a b="x" c="y" b="z">....</a>

Attribute names should never appear in quotation marks, but attribute values must always appear in quotation marks in XML (unlike HTML) using the " or ' characters. <!-- WRONG! --> <a b=x>...</a>

Page 22: Lecture 2 Overview

Thayer School of EngineeringDartmouth

ReferencesA reference allows you to include additional text or markup in an XML document. References always begin with the character “&” (which is specially reserved) and end with the character “;”.

XML has two kinds of references:

entity references An entity reference, like “&amp;”, contains a name (in this case, “amp”) between the start and end delimiters. The name refers to a predefined string of text and/or markup, like a macro in the C or C++ programming languages.

character references A character references, like “&#38;”, contains a hash mark (“#”) followed by a number. The number always refers to the Unicode code for a single character, such as 65 for the letter “A” or 233 for the letter “é”, or 8211 for an en-dash.

Page 23: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Predeclared References

Character Predeclared Entities

& &amp; < &lt; > &gt; " &quot; ' &apos;

Page 24: Lecture 2 Overview

Thayer School of EngineeringDartmouth

DTD’s ....This the syntax of an XML document.

The structure (elements, etc) of an XML documentare specified by a “schema”.

If an XML document adheres to a prespecifiedschema, it is valid....ie the syntax is compliant withthe schema.

Schemas are specified by DTD’s or XML Schema.

We’ll look at both DTD’s and XML Schema next.

Page 25: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Different types of DTD’sInternal DTD - inside .xml file

<?xml version=“1.0”?><!DOCTYPE people [ .... ]><people></people>

External DTD - file with .dtd extension<!ELEMENT ......>

“SYSTEM” (private) vs “PUBLIC”

Local extensions,rules can be added to external reference andoverride the external DTD.

Page 26: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Using a DTD from within an .xml<?xml version=“1.0” standalone=“no”?>

<!DOCTYPE people SYSTEM “http://www.dartmouth.edu/~gvc/..”>

<people>

...

</people>

Naming DTD’s using Formal Public Identifiers (FPI’s).....

Next class....structure of the DTD and XML Schema.

Page 27: Lecture 2 Overview

Thayer School of EngineeringDartmouth

Defining elements<!ELEMENT people(name,company)>

Elements name and company must be defined elsewhere,before, after or externally.

<!ELEMENT people(name+, company*)>

means name occurs at least once, company zero or more times.

<!ELEMENT nameandcomp(name|company)><!ELEMENT people(name|nameandcomp*)>

+ means at least once, ? means zero or one, * means zero or more

so (name,name,name+) means at least three time, etc.

Page 28: Lecture 2 Overview

Thayer School of EngineeringDartmouth

XMl Tutorials and References

• Let’s find a few…..• XML Parser in Visual Studio