lesson 16. extensible markup language (xml) world wide web consortium (w3c) – non-profit...

31
Lesson 16

Upload: easter-dickerson

Post on 23-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Lesson 16

Page 2: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Extensible Markup Language (XML)

• World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented the draft of XML in late 1990’s

• Inlcudes data management capabilities that HTML cannot provide

• Consider example of a list of planets– Same HTML tags are decided to be used for information of each

planet – actual list can be longer- nine planets– Explain the HTML code– Show the browser result – Shortcoming of HTML – only 6 levels of headings – problem if

each planet item has more information elements like color or size of planet

– In late 1990’s web professionals considered XML as a list formatting alternative of

Page 3: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<HTML><HEAD><TITLE>Planets</TITLE></HEAD><BODY><h1>Planets</h1>

<h2>PlanetName</h2><h3>DistanceFromSun</h3><h4>Moons</h4><h5>DayLength</h5>

<h2>Mercury</h2><h3>36 million miles</h3><h4>None</h4><h5>176 Days</h5>

<h2>Venus</h2><h3>67 million miles</h3><h4>None</h4><h5>117 days</h5>

<h2>Earth</h2><h3>93 million miles</h3><h4>One</h4><h5>24 Hours</h5></BODY></HTML>

Page 4: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented
Page 5: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

• XML differs from HTML in two important respects– XML not a markup language with defined

tags- can create own set of tags -<address>– Tags do not provide information how text

would appear on a web page, rather tags convey meaning of information included within them-tags define the meaning of facts

• To understand distinction consider the example of planets again – XML code for it

Page 6: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<?xml version=“1.0”?>

<PlanetsList>

<Planet Name=“Mercury”><Distance>36 million miles</Distance><Moons>None</Moons><DayLength>176 days</DayLength></Planet>

<Planet Name=“Venus”><Distance>67 million miles</Distance><Moons>None</Moons><DayLength>117 days</DayLength></Planet>

<Planet Name=“Earth”><Distance>93 million miles</Distance><Moons>One</Moons><DayLength>24 Hours</DayLength></Planet>

</PlanetsList>

Page 7: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

• First line of code – declaration – version 1• Root element tags – 2nd & last line – contains other

elements – assigned a name that describes purpose of file

• Other elements are child elements – country is child element of countrylist – each attribute is child element of country element

• Names of child elements can be different between two organizations- how share information – capital or capitalcity

• Many companies have agreed to follow common standards for XML tags – these standards in the form of data type definitions (DTDs) or XML schemas are available for different industries – accounting information, legal information standards etc.

• In 2001 W3C released a set of rules for XML documents

Page 8: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

• All elements must be properly nested– <outer><inner>content</inner></outer>

• All attribute values must be quoted– <FRIES SIZE=“LARGE”>

• All elements with empty content must be identified by ending in />– <BR/>

• All elements must be cased consistently– <PART> must not be closed as </part>

• Certain characters having reserved meanings cannot be used– & , <

XML has its rules!

Page 9: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

• Embedding XML into HTML documents– <XML> element can be used anywhere within

HTML document to enclose XML content -</XML>

– <script> element can also be used

Page 10: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<html><head><title>XML-example</title></head><body><h1>HTML text here</h1><xml><meal><burger><name>spicy</name></burger></meal></xml></body></html>

Page 11: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<script language=“xml” type=“text/xml”>

<weather>

<rainy/>

</weather>

</script>

Page 12: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

• Basic way to render XML is to translate it into html – server side program translates xml documents to html documents at delivery time

• We write XSL rules that match various xml elements and output the appropriate html

• XML files are translated using another file which contains formatting instructions

• Formatting instructions are often written in Extensible Stylesheet Language (XSL)

• These formatting instructions are read over by special programs – usually these programs are written in Java programming language- called XML Parsers

• Diagram how web server might process http request for an XML page – explain it

Page 13: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Web Server

PC

A web client sends an HTTP request for an XML document

XML Database

Web server requests an XML document from the XML database

The XML parser program, which can run on the XML database server or on the Web server, formats the data using a style sheet

XSL style sheet

XML parser

1

6

5

4

3

2

The XML parser sends the newly formatted XML document to the web server

The web server delivers the document to the client

Page 14: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<?xml version=“1.0”?>

<?xml-stylesheet href=“catalog.xsl” type=“text/xsl” ?>

<CATALOG>

<PART>

<NAME>Switch</NAME>

<DESCRIPTION>A very efficient device</DESCRIPTION>

<PRICE>Rs. 1000</PRICE>

</PART>

<PART>……</PART>

….

</CATALOG>

</xml>

Page 15: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<?xml version=“1.0”?><xsl><rule>

<root /><html><body bgcolor=yellow><children /></body></html>

</rule><rule>

<target-element type=“PART” /><DIV style=“margin-bottom:20px”><children /></DIV>

</rule><rule>

<element type=“PART”><target-element type=“NAME” /></element>

<B><children /><B><BR /></rule>………</xsl>

Page 16: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

HTML and XML Editors• General purpose text-editors, Notepad etc.• HTML editors available help create web pages more

easily• Web site design and creation programs or web page

builder softwares – result in one window and code in another

• Edit in one window and the result is reflected in other• Drag and drop images on web browser view page and

program automatically generates HTML tags to position it

• Macromedia Dreamweaver generates the HTML brackets automatically

• Microsoft FrontPage• Xml also in any text editor – programs include Epic

Editor, TurboXML – tag validation and editing job becomes easy

Page 17: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Web Server

• A computer that delivers (serves up) web pages with an IP address and possibly a domain.

• Any computer can be turned into a Web server by installing server software and connecting the machine to the internet.

Page 18: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Introduction to ASP

• ASP – Active Server Pages– Used to create web sites that provide user with

individualized data, Access to file system and databases and much more…

• Runs best on IIS - Internet Information Server• IIS is available free with windows NT option pack

and more popular Windows 2000• ASP engine works with any scripting language

(that is compatible with Microsoft Scripting Host requirements) but VBscript is most popular and recommended

Page 19: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Intrinsic Objects

• To use most objects from a programming language, you must first create an instance of the object you want to use. An object instance is a single copy of an object. You create an instance of an object by creating an object variable, then assigning a new copy of an object to the variable. The process is called instantiation.

• You don’t have to instantiate ASP objects. The seven objects that ASP exposes are called intrinsic objects because you don’t have to create them. They are always available for you to use on any ASP page.

Page 20: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Intrinsic Objects of ASP

• Response Object : Used to send information to the client• Request Object : Used to retrieve information included

with the request from the client• Server Object : Used to communicate with the server • Application Object : Used to store (cache) information

about you application• Session Object : Used to cache information about a

specific browser instance ( which usually, but not always corresponds to a single user)

• ObjectContext Object• ASPError Object

Page 21: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Variables in VBscript• VBSript has only one type of variables – the Variant type, but it can

hold any of three kind of values: – scalar values (meaning Boolean, Integer, long, Single, double, Date,

curreny, String)– Arrays – object pointers

• To create a scalar variable, you define varialbe using Dim statement, then you assign values to the variable Dim x x=100

• VBscript by default assumes that any symbol that is not a keyword is a variable. This might cause serious problems when you are writing an ASP application. What if you mistype a variable name and it will be considered by the server as a new variable. To avoid this you must write Option Explicit at top of your each ASP file

Page 22: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Response

• When a browser requests data from the server, the server responds, either with a redirect message, the requested data, or an error message.

• For HTML requests, the response data comes directly from the Web server, which reads and returns the content of an HTML page. For ASP pages, the response data comes from the ASP object called the response object.

• The process the web server uses to return a response might be complex but returning a response using a response object couldn’t be easier.

Page 23: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<%@ language=VBScript %><%option explicit%><%Dim lastnameDim firstnameDim myagelastname=“abc”firstname=“xyz”myage=30%><html><head><title>It is easy</title></head><body>My name is <%=firstname%> <%=lastName%> and my age is <

%Response.Write myage%></body></html>

Page 24: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Response.Write

• This function of response object can be used to write anything you like on the server side, to create dynamic contents of a web page (even HTML).

• The Write method accepts a text string.

• You must surround the text with double quotes

Page 25: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

More of Response Object

Response Object is not restricted to write function only it has much more to it.

• Response.Redirect: to redirect the page on submission or otherwise. Like Reponse.Redirect http://vu.pk.edu

• Response.Expires property when set tells the browser when it need to reload the page for exampleResponse.Expire=10 in a page will tell the browser to reload the page after 10 minutes have passed

Page 26: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Request.Form Collection

• The Request object contains information that the browser sends to the server.

• The request Object offers five different collection of information one of them is Form which contains information user enters into input controls and information your application has stored in form variables

• When a browser submits form data using post method, the ASP engine parses the raw HTTP form data and stores it in the Request.Form collection

Page 27: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<FORM NAME="regForm" ACTION="regcheck.asp" METHOD="POST" onSubmit="return checkValues()">

Name: <INPUT TYPE="TEXT" NAME="userName" maxlength="25"><P>Address: <INPUT TYPE="TEXT" NAME="userAdd" maxlength="50"><P>Login: <INPUT TYPE="TEXT" NAME="userlogin" maxlength="15"><P>Password: <INPUT TYPE="Password" NAME="userPassword"

maxlength="15"><P>Confirm Password:<INPUT TYPE="Password" NAME="conPassword"

maxlength="15"><P>Email: <INPUT TYPE="TEXT" NAME="email" maxlength="15"><P><INPUT TYPE="submit" NAME="Go" VALUE="Register!"><INPUT TYPE="RESET" VALUE="Reset!"></FORM>

Page 28: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Request .Form(“userlogin”) will give you what user has typed in userlogin text box.

Userlogin is the key for request.Form collection to retreive informationFor example (let it be regcheck.asp)

<%@ language=VBScript %><%option explicit%><%Dim loginnameDim nameloginname=Request.Form(“userlogin”)name=Request.Form(“username)%><html><head><title>It is easy</title></head><body>My name is <%Response.Write name%> and I am going to use<%Response.Write loginname%> as my login</body></html>

Page 29: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

Using other programming operatives

• VB script offers a lot of flexibility to program

• If statements

• Loops

• Many functions to handle your strings

• Much more…

Page 30: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented

<%@Language=“VBSCRIPT”%><%option explicit%><HTML><Body>Test1<%Dim myString=“ecommerce”%><%If Time>=#12:00 AM# and Time<=#12:00 PM# then%><h3>Good Morning Pakistan</h3><%else%><h3>Hello Everyone <p><%Dim jFor j=1 to 3

response.write myStringresponse.write “<p>”

Next%></h3><% end if %></Body></HTML>

Page 31: Lesson 16. Extensible Markup Language (XML) World Wide Web Consortium (W3C) – non-profit organizations that maintains standards for the web presented