IIS and ASP Overview
IIS and ASP Overview
UNIT-IV: ASP Introduction: y y y y y y y y ASP stands for active server pages. ASP is program that runs inside IIS. ISS stands for internet information services. IIS comes as free component with Windows 2000 ISS comes also a part of the Windows NT 4.0 Option pack. The option pack can be downloaded from Microsoft. PWS is a smaller-but fully functional-version of ISS. PWS can be found on your Windows 95/98 CD.
ASP compatibility: y ASP is a Microsoft technology. y To run ISS you must have Windows NT 4.0 or later. y To run PWS you must have Windows 95 or later. y Chili ASP is a technology that runs ASP without Windows OS y Instant ASP is a technology that runs ASP without Windows. What is an ASP file?: y y y y An ASP file is just the same as an HTML file. An ASP file can contain text, HTML, XML, and scripts. Scripts in an ASP file executed on the server. An ASP file has the file extension .asp.
How does ASP differ from HTML?: y y y When a browser requests an HTML file, the server returns the file. When a browser requests an ASP file, ISS passes the request to the ASP engine. The ASP engine reads the ASP file, line and executes the scripts in the file. Finally, the ASP file is returned to the browser as plain HTML.
What can ASP do for you?: y y y y y y y y Dynamically edit, change or add any content of a web page. Respond to user queries or data submitted from HTML forms. Access any data or databases and return the results to a browser. Customize a web page to make it more useful for individual users. The advantages of using ASP instead of GGI and PERL are those of simplicity and speed. Provides security since your ASP code can not be viewed I any browser. Since ASP files are returned as plain HTML, they can be viewed in any browser. Clever ASP programming can minimize the network traffic.
INTRODUCTION TO ACTIVE SERVER PAGES (ASP): ASP (Active server pages) is a platform for creating interactive web sites. ASP was created by Microsoft. It was designed to be easier to use, faster to develop in, and to perform better than Perl/CGI. You can perform ASP in a # of scripting languages, but the primary scripting language used today is VBScript and Jscript. ASP was born in November 1966 when Microsofts ideas about how a desktop computer and the active server the active desktop refers to the client side, or the user side, where HTML files are displayed on a web browser. Active Server Pages an open, compile-free application environment in which we can combine HTML, scripts, and reusable ActiveX server components to create dynamic and powerful Web-based business solutions. Active Server Pages enables server-side scripting for IIS with native support for both VBScript and Jscript. ASP files combine HTML, scripts, and ASP code to enable a much higher degree of interactivity possible with plain vanilla HTML. With ASP, programmers working on Windows NT can tailor the pages are displayed based on outside information. A different image could be displayed each day of the work, or information could be displayed based on a users age. IMPORTANCE OF ASP: y Using ASP, users can generate dynamic web pages. An active server page can display different contents to different users or display different content at different times of the day and also different place. Depending upon the users identity and previous choices also, pages can be served. Process the contents of HTML forms. You can use an active server page to retrieve, manipulate and respond to the data entered in to a HTML form.
Web Programming
y y y y y y
Create database driven Web pages. An Active server page can insert new data or retrieve existing data from a database such as oracle or Microsoft SQL Server. Track user sessions you can use active server pages to store information about users from the moment they arrive at your Web site till the moment they leave(i.e. while they are on the site). Create searchable Web pages. When used with Microsoft index server or Microsoft SQL server full-text search, ASP enables you to create search engine for your web site. Detect the capabilities of different browsers. An Active server page can detect the features that a browser supports display content that is appropriate to different browsers. Send and retrieve email. An Active server page can automatically generate and send email to users and retrieve email sent to your Website. Integrate custom components into your Web site. You can extend your Active server page scripts with custom server components created with Microsoft script components such as Microsoft visual Basic or Microsoft Visual C + +.
PERSONAL WEB SERVER: Many of the users still do a lot of our programming on the Win 95 platform. Personal Web Server (PWS) is a surprisingly powerful utility for turning the Windows 95 client machine into a de facto web server. This proves extremely useful for coding and debugging yours ASP script. But for those of us who are new to web site development, personal web sever provides a list daunting challenges. PWS is actually bundled in side NT option pack 4 , but user can follow the instructions to download just the PWS components. You will download a file called [Link] which is around 9.6 MB in size, so find high speed connection if one is available to you. Once the installation is complete, you will find a new addition to your program menu. This installation is automatically installing ASP version 1.0 to your system, which is an order of version of ASP. ACTIVE SERVER PAGES (ASP): Microsoft Active Sever Pages is a server side scripting environment that we can use to create and run dynamic, interactive, high performance web server applications. When the script runs on the sever rather than on the client, our web server does all the works involved in generating the hyper text mark up language(HTML) page that you send to browser. ASP is a feature of and can be used with following web servers: y y y Microsoft internet information server 3.0 and 4.0 on Windows NT server. Microsoft peer web server version 3.0 and 4.0 on Windows NT workstation. Microsoft Personal Web Server on Windows 95 and 98.
ASP is an ISAPI extension which build on top of the ISAPI infrastructure to provide a sever side application frame work, making it even easier to build dynamic web applications. It is important to distinguish between HMTL and DHTML and dynamically created HTML. Dynamically created HTML is where the contents are generated on the fly on the server using mechanism like CGI, ISAPI, or ASP.
INTERNET
ASP enables the scripting logics to interface with member of ASP institute objects, which automatically handles many of the tiny tasks, and so simplifies the amount of development required. These objects provide ASP with the concept of the user session and allow variables to persist across web pages, until either the session is programmatically abandoned or the web browser is closed. In addition, the real power of ASP scripting comes from its ability to interface with external COM complaint software components, including those supplied with ASP, those provided by Windows NT and other back office products, and those developed by ourselves and other independent software venders. FEATURES OF ASP:
Web Programming
Include rotating banner advertisement on pages of web site. Retrieve information entered in HTML form and store that information in a database. Create personalized web pages that display different content to different users. Add hit counters to one or more pages of web site. Display different Web Pages depending on the capabilities of the users Web Browser. Link together multiple web pages in such a way that they can be navigated easily.
THE APPLICATIONS OF ASP: ASP enables the inclusion of executable scripts directly in HTML files. HTML development and scripting development becomes the same process, freeing the programmer to focus directly on the look and feel of a web site, weaving dynamic elements unto your pages appropriate. ASP applications are: y Completely integrated into HTML files y Easy to create, with no manual compiling or linking of programs required y Object Oriented and extensible with Active-x server components. This enables web provides to provide interactive business applications rather than merely publishing content. ASP applications are easy to develop because ASP scripting is used to develop them. With ASP scripting, any scripting language can be used for which there is an appropriate scripting engine to use with the web server. ASP supplies scripting engines for Microsoft visual basic scripting edition (VBSCRIPT) and Jscript. Sophisticated functionality can be brought to web pages by using Active server components, formerly know as automation servers, to process data generate useful information. Since the output of an ASP program is standard HTML, ASP generated content is compatible with all standard web browsers. ASP SCRIPT:-A script is a series of sentences placed one below the other in the form of paragraph. Each sentence tells the CPU what it should be doing at that moment in time. The sentences will be written in the syntax of the scripting language of choice. Thus the paragraph created will be the script. For example y y y y Assign a value to a variable. A variable is a named storage location that can hold data. Instruct the web server to send something, such as the value of a variable, to a browser. Combine commands into procedures. A procedure is a named sequence of commands and statements that acts as a unit. Executing a script sends the series of commands to a scripting engine, which interprets and relays them to the computers CPU. Scripts are written in languages that have specific grammar hence. To use given scripting language, the web server must have scripting engine that understands the language. ASP provides scripting engines for the VBSCRIPT and JSCRIPT languages.
PROCESS OF SERVING AN ASP PAGE: A user enters the internet address of an Active Server Page file into the address/location bar of a web browser. The browser sends a request to the server for an Active Server Page. The web server receives the request and recognizes that the request is an Asp file because the requested file has the extension of ASP. The web server retrieves the proper Active server page file from disk memory. The web server sends the file to a special program named the ASP dli commands encountered are executed. The result of this process is a standard HTML file. The standard HTML file is sent back to the browser.
From the perspective of the web server, an Active server pages is very different from a normal HTML page. A normal HTML file is sent without any processing to the browser. All the commands in an Active server page, on the other hand, must first be executed to create an HTML page. This allows an Active server page to contain dynamic content. From the perspective of the web browser, on the other hand, an Active server page is almost exactly the same as a normal HTML page. The only difference is that an Active server page typically must end with the extension rasp rather than HTML. When a request is made for an Active server page, the browser receives a normal HTML page, which is the output of the .asp file being processing, this enables an Active server page to be compatible with all browsers.
Web Programming
ASP CODE: When a programmer writes an ASP page, it is likely to be of a combination of three types syntax-some ASP, some HTML tags, and some pure text.
purpose This is hard coded information to be shown to the user. This consists of instructions to the browser about how to format text and display images. This consists of instructions to he web server running ASP about how to create portions of the page to be sent out. The file containing these constituent parts of the ASP page is saved with an. asp extension. Anything that falls between the <% and %> markers is ASP script and will be processed on the web
For example, consider the few lines code below... <HTML> <p> this date/time is now :< %=NOW () %> < /p> </HTML> This content of the resulting web page depends on the HTML that is generated by the ASP code. In this particular example, the effect of the script code is to generate HTML for the time and date that page is requested, and then to make decision on what text will be sent to the browser as a part of HTML stream. ASP SYNTAX, DELIMITERS, STATEMENTS: ASP technology is not a scripting language, rather, ASP provides an environment that process scripts that are incorporated into HTML pages. To use ASP successfully, its scripting syntax. Delimiters:-HTML tags differentiated from text by delimiters. A delimiter is a character or sequence of characters that marks the beginning or end of a unit. In case HTML, these delimiters are the less than (<) and grater than (>) symbols. Similarly, ASP script commands and output expressions are differentiated from the text and HTML tags by delimiters. ASP uses the delimiters <% and %> to enclose scripts commands. For example, the command <% port climbing %> assign the value climbing to the variable sport. Scripting language:-Scripting languages focus on formatting text or calling and using compiled components written in a programming language. Active server pages make it possible for the web developer to write complete procedures by using a variety of scripting languages. In fact, several languages can be used within a single asp file. In addition, because scripts are read processed on the server side, the client browser that requests the. Asp file does not need support scripting. Setting the scripting language: The ASP scripting language used to process commands inside the <5 and %> delimiters. By default, the scripting language is VBScript. You can use any scripting languages for which you have a script engine as the scripting language. You can set the scripting language on page-by-page basics, or for all pages in an ASP application. To set the scripting language for a single page, add the <%LANGUAGE %> directive to the beginning of your .asp file the syntax for this directive is: < % LANGUAGE=scripting language %> where scripting is the scripting language that you want to set for that particular page. The setting for a overrides the global setting for all pages in the application.
Web Programming
ASP APPLICATION: An ASP-based application consists of a virtual directory on web-server and all the folders and files within that virtual directory. An ASP application can be simple home page: it can include a number of dynamic elements or it can consist of a complex set of interrelated and pages and logic. When you use ASP- based applications, you are able to maintain state. State is the ability to retain in information .you can use ASP to maintain two types of state: 1. Application state, in which all information pertaining to an application is available to all. users of an application. 2. Session state, in which information is available only to a user of a specific session. Session and application objects: The ASP tools you use to manage state are the session and allocation built-in-objects you can use the ASP built- objects, session and application to extend the functionality of your ASP-based application. Use the session object manages information for a user is using an application A session belongs, in effect, to a single user. The application object is used to store common information that can be shared between all users of a single ASP-based application. ASP INTRINSIC OBJECTS: The two main intrinsic objects: the request and response object map directly to the request and the response which the HTTP protocol uses to transfer information between the client and the web server. The other four objects provide a number of functions that are useful in scripting our ASP applications. Each intrinsic object provides a range of methods, properties and collections. The application object is created in response to the first request for an ASP Page it provides repository or storing variables and object references that are available to all visitors accessing our site for the entire duration of our ASP application. The ASP error object is a new object in ASP 3.0 it provides a range of detailed information about the last error. That accrued in ASP it is used with in the customer error pages. The response object is used to create the response sent back to the client. It enables our scripts or components to use the HTTP variables for the server, information about the contents we are sending to the browser, and any new cookies we are going to store in the browser. In addition it provides methods to creating out put, such as [Link] methods. The session object is created for each client or visitor when they first request an ASP page. It provides a repository for storing the variables and object references that are available only to the pages that this visitor opens during the life time of the session. This is very important way to maintain state. RESPONSE AND REQUEST OBJECT: ASP objects: the two main objects are the response and request object map directly to the request and response which the HTTP protocol uses to transfer information between the client and web server. Response: The ASP response object is used to send out put to the user form the server. Its collections, properties and methods are described below. Collections: Cookies: sets a cookies value. If the cookies does not exists, it will be created and take the value that is specified. Properties: Buffer: specifies whether to buffer the page out put or not Cache Control: sets whether a proxy server can catch the out put generated by ASP or not. Char set: appends the name of character set to the content type header in the response object. Content Type: Set the HTTP content type for the response object. Expires: Sets how long page will be cached on a browser before it expires. ExpiresAbsolute: Sets a date and time when a page cached on a browser will expire. IsClientConnected: Indicates the client has disconnected from the server Pics: Appends a value to the PICS label response header Status: Specifies the value of the status line returned by the server Methods: AddHeader: adds a new HTTP header and a value to the HTTP Response AppendToLog: Adds a string to the end of the server long entry BinaryWrite: Writes data directly to the output with out any character conversion Clear: Clears any buffered HTML out put End: Stop processing a script, and returns the current results. Flush: Sends buffered HTML out put immediately Redirect: Redirects the user to a different URL Write: Writes a specified string to the out put Request: When a browser asks for a page from a server, it is called a request. The ASP request object is used to the information from the user. Its collections, properties and methods are given below:
Web Programming
Collections: ClientCertificate: Contains all the fields value stored in the client certificate. Cookies: Contains all the cookies values sent in a HTTP request. Form: Contains all the form values from a form that uses the post method. QueryString: Contains all the variables value in a HTTP Query string. ServerVariables: Contains all the server variable values Properties: TotalBytes: Returns the total number of bytes the client sent in the body of the request. Methods:
BinayRead: Retrieves the data sent to the server from the client as part of a post request and stores in a safe array. APPLICATION OBJECT: An application on the web is a group of ASP files these files work together to perform some purpose. The ASP application object is used to tie these files together. The ASP application object is used to store variable and access variables from any page. All users share one application object. The application object should hold information that will be used by many pages in the application this means that you can access the information from any page. It also means that you can change the information in one place and the new information will automatically be reflected on all pages. Its collections, methods, and events described below: Collections: Contents:-contains all the items appended to the application through a script command. Static objects:- contains all the objects appended to the application with the HTML <Object>tag Methods: Contents:-Remove deletes an item from the contents collection. Contents:-Remove all deletes all items from the contents collection. Lock:-prevents other users from modifying the variables in the application object. Unlock:-Enables other users tom modify the variables in the application object Events:Application_Onend:-occurs when all user sessions are over, and the application ends. . Application_Onstart:-occurs before the first new session is created. SESSION OBJECT: The ASP session object is used to store information about, or change settings for a user session. Variables stored in the session object hold information about one single user, and are available to all pages in one application. Common information stored in session variables are- name, id, and references. The server creates a new session object for each new user, and destroys the session object when the session expires. it collection, properties, methods, and events are described below. Collections: Contents: Contains all the items append to the session through a script command Static objects: Contains all the objects append to the session with the HTML<object> tag Properties: Codepage:- specifies the character set that will be used when displaying dynamic content. LCID:-sets or returns an integer that specifies a location or region. Content like date, time and currency will be displayed according to that location or region. Session ID:- returns a unique id for each user. The unique id is generated by the server Timeout:-sets or returns the time out period for the session object in this application. Methods: Abandon destroys a user session Contents: remove deletes an item from the content collections Contents:- remove All deletes an all item from the content collections Events Session_Onend:-occurs when a session ends Session_Onstart:-occurs when a session start
Web Programming
SERVER OBJECT: The ASP server object is used to access properties and methods on the server. Its properties and methods described below. Properties Script timeout:-sets or returns the maximum number of seconds a script can run before it is terminated Methods Create object Create an instance of an object Execute:-Executes an ASP file from inside another ASP file Getlasterror:-Returns an ASP error object that describes the error condition that occurred HTMLencode:Aplies HTML encoding to a specified string. Mappath:-Maps a specified path to a physical path. Transfer:-Sends all the information created in one ASP file a second ASP file URLencode:-Applies URL encoding rules a specified string. ASP ERROR OBJECT: The ASP Error object is implemented in ASP 3.0 and it is only available in 1155. The ASP error object is used to display detailed information of any error that occurs in scripts it an ASP page. The ASP error object is created when server. GetLastError is called, so the error information can only be accessed by using the [Link] method. The ASPerror objects properties are described below. Properties ASPcode:-Returns an error generated by us SPDescription:-Returns a detailed description of the error Category: Returns the source of the error Columns: Returns the column position within the file that generated the error. Description:-Returns a short description of the error. File:-Returns the name of the ASP file that generated the error Line:-Returns the number where the error was deleted Number:- :-Returns the standard COM error code for the error Source:-Returns the actual source code of the line where the error occurred. DRIVE OBJECT: The drive Object is used to return information about a local disk drive or a network share. The Drive object can return information about a drives type of file system, free space, serial number, volume name and more. To work with the properties of the drive object, you will have to create an instance of the drive object through the FileSystemObject. First create a FileSystemObject object and then instantiate the drive object through the GetDrive method or the Drive property of the FileSystemObject. DICTIONARY OBJECT: The Dictionary object is used to store information in name/value pairs (referred to as key and item). The Dictionary object might seems similar to arrays, however, the Dictionary object is a more desirable solution to manipulate data. y Keys are used to identify the items in a dictionary object y You do not have to call ReDim to change the size of the Dictionary object. y When deleting an item from a dictionary, the remaining items will automatically shift up. y Dictionaries cannot be multidimensional. Arrays can y Dictionaries work better than arrays on accessing random elements frequently. y Dictionaries work better than arrays on locating items by their content. The Dictionary objects properties and methods are described below. Properties: Compare Mode: Sets or returns the comparison mode for comparing keys in a Dictionary object. Count Returns the number of key/item pairs in a Dictionary object. Items Sets or returns the value of an item in a Dictionary object. Key sets a new key value for an existing key value in a dictionary object. Methods: Add Adds a new key/ item pair to a Dictionary object. Exists Returns a boolean value that indicates whether a specified key exists in the Dictionary object. Items Returns an array of all the items in a Dictionary object. Keys Returns an array of all the keys in a Dictionary object. Remove Removes one specified key/item pair from the Dictionay object. RemoveAll Removes all the key/item pairs in the Dictionary object <% Dim d
Web Programming
Set d= [Link]([Link]) [Link] re Red [Link] gr,Green [Link] bi,blue [Link] pi,pink [Link](The value of key gr is:&[Link](gr)) %>
BROWSER CAPABILITIES: The ASP Browser capabilities component creates a BrowserType object that determines the type, capabilities and version number of each browser that visits your site. When a browser connects to a server, an HTTP user agent header is also sent to the server. This header contains information about the browser (like browser type and version number). The browser type object then compares the information in the header with information in a file on the server called [Link]. If there is a match between the browser type and version number sent in the header and the information in the [Link] file, you can use the browsertype object to list the properties of the matching browser. If there is no match for the browser type and version number in the [Link] file, it will set every property to UNKNOWN. Syntax: <% Set MyBrow=[Link]([Link]) %> DATA ACESS: Using the ActiveX Data objects (ADO), we can store and retrieve data from a variety of data providers. For example, we can use the ADO to access information from Microsoft Access and the Microsoft SQL and Oracle database servers. We can even use the ADO to retrieve information from Microsoft Excel spreadsheet. The ActiveX data objects consist of seven independent objects. y y y y y y y Connection object: Represents a unique session with a data source. For example, we can use the connection object to open a connection to MS SQL Server. Recordset object: Represents a unique session with a data source. For example, we can use the connection object to open to open a connection to MS SQL server. Field object: Represents an individual field in a recordset. Command object: Represents records. For example, you can use the command object to execute a SQL stored procedure or a parameterized query. Parameter object: Represents an individual parameter in a SQL stored procedure or parameterized query. Property object: Represents data-provider-specific properties. Error object: Represents ADO errors.
When using the ADO, we shall be most directly interacting the connection, recordset, and command objects. Configuring data source: A data source contains information about how to connect to a data provider. There are three types of data sources: we can create a user data source, a system data source, or a file data source. When creating a data source to use with a web server, we should create a file data source. The advantage of creating a file data source is that the connection information is stored in a file, more than one user can access this file, and also we can easily transfer file as and when we transfer the web application. Steps to create a file data source: y y y y y y y y y Open windows control panel. Click the icon labeled ODBC. Click the file DSN tab. Click the Add button. The create new Data source dialog bx appears. Give the appropriate information and click OK. There are three major steps to access the data from a database. Create connection object. Open the connection using appropriate data source. Execute SQL commands.
SQL statements using Execute method in ASP: Executing SQL statements: to execute a SQL statement with an open connection, we can use Execute method. This method has two forms: one form is used when retrieving results from a database; and the other form is used when no results are returned. The following example shows how we can use the execute method to execute a SQL statement that doesnt retrieve any results: <% Set myconn=[Link]([Link]); [Link] FILEDSN=dsnPath [Link] insert into student values(1,shivani,400) [Link] %>
Web Programming
In this example, the execute methods is used to execute a SQL INSERT statement, because no results are returned. We can also use the Execute method to return results are returned. We can also use the Execute method to return results from a SQL query, as in this example. <% Set myconn=[Link](ADODB>Connection); [Link] FILEDSN+dsnPath Set RS= [Link](select * from student) [Link] %> The results of the SQL query are retrieved into an instance of a recordset object named RS. This recordset is automatically created by the execute method. The execute method includes two optional parameters. We can provide a records affected parameter that indicates the number of records that the SQL statement affected parameter that indicates the number of records that the SQL statement affected. We can also include an optional parameter that provides information about the type of SQL statement being executed. Example: <% [Link] update employee set sal=sal+2000 where desg=Manager [Link] %> In this script, the SQL UPDATE statement will update the employee table, whose designation is manager. The execute method also has two additional parameters. The first parameter is the records Affected parameter, it includes the number of records updated after executing the SQLQuery. Recordset object:: A recordset can be used to represent the records in a database table. Like a table, a recordset contains one or more records. Each record contains one or more fields. At any given moment, only one record is the current record. As we discussed in the previous topic, we can create recordset object using Ececute() method of the connection object. To display all the records in the recordset, we can simply loop through the records. Example: Set myconn=[Link]([Link]) [Link] FILEDSN <dsn path> Set [Link](select * from students) WHILE NOT RS>EOF [Link](<BR> rajitha RS(stdno) rajitha RS(name) & RS(marks) RS>MoveNext WEND [Link] [Link] %> In this example, the whilewend loop is used to move through each reord4 contained in the RS Recordset. All students number, name and marks are outputted to outputted to the browser. This script displays all the records contained in the student table. Information Search Tools: the Microsofts indexing service provides one solution to the problem of retrieving our information for many data sources. The indexing service allows us to index diverse and distributed files and documents, and provides users the ability to search the contents of these files and associated data. The indexing service enables us to provide a quick and accurate way for users to search information, by providing us with ready-build tools and services to catalog the information and manage these catalogs. Using the indexing service to set up catalog and handle the gathering of information becomes an administrative task. Three main activities are performed by the indexing service: managing, querying, and filtering. The most interesting of the gathering of information becomes an administrative task. The indexing service allows us to provide users with an application that enables them to locate information quickly and precisely. This application usually takes the form of a web search page in which users details about the information they wish to access, combined with code to perform a query and display the results. The indexing service provides a query object that can be used to create search pages that have very specific search criteria. For, example, we could create a web page that enables a user to enter the name of a product produced by a particular company, and search a central document repository of the companys products specifications .the user would then get a list of the documents in the, repository related to that-product.
Web Programming
The Microsoft indexing service, introduced with windows2000, evolved form Microsoft index server, available from the Windows NT 4.0 option pack. The expanded capabilities include: There are two languages that can be used for querying the indexing services. The indexing service query language (ISQL), and structured Query language the standard language for database queries. The former uses the [Link] type library, whereas SQL uses ADO with the msidxs data provider. SQL is much more flexible than ISQL in the type of Queries that can be done, and also faster. Queries using SQL are based on extensions to the SQL querying language designed for use with the indexing service. INDEXING SERVICE OBJECT: Indexing service object model: the indexing service object model has the following objects: y AdminIndexServer. y catAdmin. y ScopeAdmin. y Query and y Utility. The Query and utility objects are provided in the [Link], while the others are in [Link] a split which mirrors a division in functionality. The [Link] objects are intended for administering the indexing service, whereas the [Link] objects are used when working with queries.
UNIT V: XML Introduction to XML: Extensible Markup Language is an abbreviated version of standard generalized markup language (SGML) for the exchange of structured documents over the internet. XML enables the definition, transmission, validation and interpretation of data between differing computer platforms and applications. XML is extensible, meaning a developer can extend the language by defining new tags to describe and share data. The new tags follow the XML syntax defined by the XML Specification. XML is very useful for organizations that do not share but need to develop a common data exchange format. How does XML work? : XML is not programming language but a markup specification language. A browser or other application must read the XML document in order to make it something. Developer of XML documents beings with identification and definition of the data elements that will be displayed or exchanged. The data elements are defined using tags. That indicate what a data element represents.
10
Web Programming
WHAT IS XML SCHEMA?: An XML schema is a single file or collection of files that serve as the frame work for defining the data content format and structure of an XML document. A well written schema allows computers to validate the data against the rules written to describe the data. It provides a means for defining the structure and content of XML documents. IMPORTANCE OF XML: 1. The universal data format for integrated electronic business solutions: Relational database systems cannot meet all the demands of electronic business because they process data independently of its context. Traditional databases may be well suited for data that fits in to rows and columns. But can not handle rich data such as audio, video or complex documents. XML databases store XML data in its structured, hierarchical form queries can be resolved much faster. 2. Self describing data: XML does not require relational scheme, file description tables, external data type definitions etc. because data itself contains this information 3. Complete integration of all traditional database and formats: XML documents can contain classical data like text and numbers or multimedia objects such as sounds. 4. Modifications to data presentation: We can change look and feel of documents websites with XSL styles sheets with out manipulating the data itself. 5. One server view of distributed data: XML documents can consist of data from many different databases distributed over multiple servers. With XML the entire World Wide Web is transformed into a single database. 6. Internationalization: XML supports multilingual documents and other state off the art elements when needed. 7. Future oriented technology: XML is endorsed industry standard of w3c and is supported by all software provides. XML is the standard to day in an increasing number of other industries. 8. Open and Extensible: XMLs open structure allows us to add other state-of-the-art elements when needed.
XML BENEFITS: 1. Simplicity: Information coded in XML is easy to read and understand, it can be processed easily. 2. Openness: XML is a w3 standard, endorsed by software industry market leaders. 3. Extensibility: There is no fixed set of tags. New tags can be created as they are needed. 4. Self Description: In traditional databases, data records require schemas setup by the database administrator, because they contain metadata in the form of tags and attributes. Xml provides a basis for author identification at the element level. 5. Contains machine readable context Information: Tags, attributes and element structure provide context information that can be used in highly efficient search engines, intelligent data mining. 6. Separates content from presentation: XML tags describe meaning not presentation. Xml document look can be changed without touching the content. 7. Supports multilingual documents and Unicode: This is important for internationalization of applications. 8. Facilitates the comparison and aggregation of data: The tree structure of XML documents allows documents allow documents to be compared and aggregated efficiently element by element. 9. Can embed multiple data types: XML documents can contain any possible data types from multimedia data to active components. 10. Can embed existing data: Mapping existing data structures like file systems or relational databases to xml is simple, it covers all existing data structures. 11. Provides a one server view for distributed data: Xml documents can consist of nested elements that are distributed over multiple remote servers. XML is currently the most sophisticated format for distributed data. 12. Rapid adoption by industry: Some software companies will use xml as the exchange format for its office product line. Microsoft has announced support for xml through the SAP business connector. COMPONENTS OF XML: XML is based on the concept of document composed of a series of entities. Each entity can contain one or more logical elements. Each of these elements can have certain attributes that describe the way in which it is to be processed. XML provides a formal syntax for describing the relationships between an xml documents. XML differs from other markup languages in that it doesnt indicate where a change of appearance occurs, or where a new element starts. XML sets out to clearly identify the boundaries of every part of a document. XML ELEMENTS AND ATTRIBUTES: Elements are building blocks of a document. An element consists of a start tag, and end tag and the content between them. Within single element there may be multiple levels of nested sub elements which keep the individual pieces of data in a logical and easy to manage structure. The organization of elements in this fashion is called nesting. Element nesting creates parent/child relationships, and every child element resides completely within its parent element.
11
Web Programming
XML elements are extensible. XML documents can be extended to carry more information. Elements can have different content types. An XML element is every thing from including the elements start tag to including the elements end tag. An element can have element content, mixed content, simple content, empty content. Element content contains other elements. Mixed content contains both text and other elements. Simple content contains only text. Empty content carries no information. XML elements must follow these naming rules Names can contain letters, numbers, and other characters Names must not start with a number or punctuation character Names can not contain spaces XML elements can have attributes in the start tag. Attributes are used to provide additional information about elements. An attribute consists of an attribute name and an attribute value. The attribute name presides its value and they are separated by an equal sign. The attribute value is enclosed in quotes to delimit multiple enclosed in quotes to delimit multiple attributes in the same elements. USAGE OF XML: To use a set of markup tags, users need to know, how the markup tags are delimited from normal text and in which order the various elements should be used. Elements and their attributes are entered between matched pairs of angle brackets (<>), while entity references start with and symbol and end with a semicolon. XML tags are based on the logical structure of the document, they are easier to understand. The start and end of each logical element of the file has been identified by entry of a start tag and an end tag. To define tag sets users must create a document type definition that identifies the relationships between various elements that form their documents. FEATURES OF XML: XML is a compliment to html: web development xml will be used to describe the data, while html will be used to describe the data, while HTML will be used to format and display the same data. XML is cross platform, software and hardware independent tool for transforming information. 2. XML can separate data from html: When HTML is used to display the data, the data is stored inside HTML. With XML, data can be stored in separate the XML files. XML is used to exchange data: With XML data can be exchanged between incompatible systems. 3. Converting the data to XML can greatly reduce complexity and create data that can be read by many different types of applications. 4. XML and B2B: With XML financial information can be exchanged over internet. XML is the main language for exchanging financial information between business over internet. 5. XML can be used to share data: XML data is stored in plain text format; XML provides a software and hardware independent way of sharing data. 6. XML can be used to store data: XML can be used to store data in files or in databases. Applications can be written to store and retrieve information and generic applications can access xml files as data sources. XML can be used create new language: The wireless markup language (WML), used to markup 7. internet applications for devices like mobile phones, is written in XML. 1. RULES FOR DEFINING XML SYNTAX: All XML elements must have a closing tag. XML tags are case sensitive. All XML documents must have a root tag The first tag in an xml document is the root tag. All tag XML documents must contain a single tag pair. To define the root element. All other elements must be nested within the root element. Attribute values must be always quoted. With XML, white space is preserved stored as LF (Line Feed) The Syntax of writing comments in xml is <!and-->
DIFFERENCES BETWEEN XML AND HTML XML was designed to carry data. HTML was designed to display data and to focus on how data looks HTML is about displaying information, while XML is about describing information XML tags are not predefined, we must invent our own tags. The tags used in HTML documents and the structures of html documents are predefined. HTML is a presentation language, where as XML is not either programming language or a presentation language. XML is used to transfer data between applications and databases. HTML is not case sensitive, XML is case sensitive. In XML it is mandatory to close each and every tag, whereas in HTML it is not required.
12
Web Programming
DOCUMENT TYPE DEFINITION (DTD): Document Type Definition defines the structure and the content of an XML document, there by allowing us to store data in a consistent format. It specifies the elements that can be present in XML document. The DTD is a set of rules that define the elements that may be used, and where they may be applied in relation to each other. A simple XML document <xml version=1.0> <basket> A fruit basket. <oranges count=5> navel </oranges> <apples count=3> granny</apples> <peaches count=2 > red heaven </peaches> <grapes count=1> concord</grapes> </basket> The Document Type Definition for above example. <xml version=1.0> <! DOCTYPE basket [ <! ELEMENT basket (oranges/apples/peaches/grapes)> <! ELEMENT oranges (#PCDATA)> <! ATTLIST oranges count CDATA # required)> <! ELEMENT apples (#PCDATA) <! ATTLIST APPLES COUNT CDATA # required > <! ELEMENT Peaches (# PCDATA) <! ATTLIST Peaches count (DATA # required> <! ELEMENT grapes (#PCDATA) <! ATTLIST grapes count (DATA # required > ]> The DTD can be either internal DTD or external DTD. The DOCTYPE declaration is the container for all other DTD declarations. It is placed at the top of an XML document to associate the given document with a set of declarations. The name of DOCTYPE must be same as the name of documents root element. Element declaration defines an element of the specified name with the specified content model. It has the following format. <! Element element. name content mode> ATTLIST declaration defines the set of attributes that are allowed on a given element. Each attribute in the set has a name, type and default declaration. It has the following format. <! ATTLIST element. Name attribute name attribute type default value> The external DTD exists outside the content of a document and contains the extension. DTD DIFFERENCES BETWEEN WELL FORMED DOCUMENTS AND VALID DOCUMENTS: W3C in the XML specification has defined certain rules that need to be followed while creating XML documents. The examples of such rules include: having exactly one root element, having end tag for each start, using quotes for attribute values and so on. If an XML document follows all these rules, it is said to be well formed document. XML parsers can be used to parse and process such documents. Document Type Definitions can be used to define the structure and content of a specific class of XML documents. This includes parent child relationship details, attribute list, data type information, value restrictions, etc. in addition to the well formed rules, if an XML document also follows the rules specified in the associated DTD, it is said to be valid XML document. The main difference between Well Formed XML and valid XML is document type definition. XML SCHEMA: XML schema is an XML based alternative to DTD. An XML schema describes the structure of XML document. XML schema language is also referred to as XML schema definition.(XSD). The purpose of an XML schema is to define the legal building blocks of an XML documents. An XML schema 1. 2. 3. 4. 5. 6. 7. 8. Define elements that can appear in a document. Define attributes that can appear in a document. Defines which elements are child elements. Defines the order of child elements. Defines the number of child elements Defines the whether an element is empty or can include text. Defines data types for elements and attributes. Defines default and fixed values for elements and attributes.
XML schema will be used in most web applications as a replacement, for DTD. Here are some reasons. 1. Xml schemas are extensible to future additions.
13
Web Programming
2. 3. 4. XML schemas are written in XML. XML schemas support data types. Xml schemas support name spaces.
XML PARSERS: Any system that uses XML requires two components An XML processor and parser. The system application, this could be a browser.
The processor checks to make sure that the XML file follows the XML specifications. In other words, it makes sure that the file is well formed XML. It is the job of the XML parser to read the XML file and create its document tree. A document tree is a hierarchical organization of the data content. The system application then processes the data in the tree. Parser can be used for checking the XML document syntax and structure. This is done by checking the documents validity against its DTD. If the parser reads the file against the DTD description, it is known as validating parser. The next step is to break the document into its elements and store them in the source tree. If an XSL processor is used, this data is then passed on to the XSL processor, which applies the formatting rules according to the template rules. This creates a result tree. The result tree is then formatted, enhanced and manipulated by the browser and displayed. XML style sheets: CASCADING STYLE SHEETS: Style sheets contain the rules that declare how the data of an XML document should appear or be interpreted by the browser. This is done by assigning a style to a tag. This style is then applied to the data contained with in the tag. Style sheets can be written in several languages. Cascading style sheets (CSS), an extension of HTML Extensible style sheet language.(XSL), an XML specific styling language. 1) Cascading style sheets: Cascading style sheets are used to display an xml file in a consistent format. CSS is kept separate from the XML document. The browser is able to combine the XML document and format it according to the rules of CSS. While CSS can format XML document for display there are a no of problems with using CSS and XML. 2) Extensible style sheet language.(XSL): XSL is language for expressing style sheets specifically for use with Xml. It consists of two parts
a). XSLT(Extensible style sheet language transformer): XSLT is a language for transforming XML documents. XSLT engines are used to covert XML into a strict for of html. b). FO(Formatting Objects): FO is an XML vocabulary for specifying formatting semantics. These two parts for the basis of XSL style sheet that describe how the structured content of the XML data file should be displayed. An XSL style sheet is a template with rules that govern an XML document. An XSL style sheet contains tags, elements and attributes. The template rules of XSL document has two parts 1. 2. Patterns are used to select specific elements in the document. Patterns: Actions: Actions are used to describe what styling is to be applied to the element.
While using an XSL processor, the formatting specify in the style sheets is applied to the XML document elements. XML DATA BINDING: Data binding refers to mapping, synchronizing, and transporting data from a source to an end-user document, and involves data manipulation, filtering, sorting, or searching on the local system. One advantage of data binding is clientside data manipulation, which reduces client-server communication, network traffic, and server workload, and can increase client efficiency. Another advantage is the separation of data maintenance tasks from presentation and formatting tasks. An advantage of using XML to store data is the document type of XML documents, many different applications read plain text. Data binding in Internet Explorer, can be used to connect HTML files and text files to Data Source Objects (DSO) in a web page and bind DSO to HTML controls like text fields and other HTML elements. With XML data binding, there is a cross-platform compatibility issue. A disadvantage of XML data binding is the lack of universal support by browsers. XML data binding is especially suitable for a closed Microsoft environment, such as Intranet. XML data binding requires attaching a web page to a record set, called a data island. XML data binding refers to a means of representing information in an XML document as an object in computer memory. This allows applications to access the data in the XML from the object rather than using DOM or SAX to retrieve the data from a direct representation of the XML itself. An XML data binder performs this by automatically creating a mapping between elements of the XML schema of the document we wish to bind and members of a class to represented in memory. Then this process is applied to convert a XML document to an object, it is called unmarshalling. The reverse process, to serialize an object as XML, is called marshalling.
14
Web Programming
HYPERLINKS IN XML: X-Link stands for XML Linking Language. X-Link allows XML documents to establish a linking relationship between more than one document and create linking documents that reside in a separate location from the linked documents. In XML, any element can become a source of link. An element that contains a link is called a linking element. XML links are of two types: 1. Simple Links 2. Extended Links A Simple Links can be used for purpose that approximates the functionality of a basic HTML. A link can support a limited amount of additional functionality. Simple links have only one locator and thus combine the functions of a linking element and a locator into a single element. As a result of this combination, the simple linking element offers both a locator attribute and all the link and resource semantic attributes. An Extended Link differs from a simple link in that it can connect any number of resources. It can be used to create links to other documents from your documents. Extended links are of two types: Out-Of-Line links and multi-directional links. A linking element may contain optional semantic attributes. These optional semantic attributes describe the function of linked resources for both human readers and XML processors. XLINK:TITLE attribute is human readable string describing the linked document. If a value exists for this attribute, it is the responsibility of XML processing application to access and display it appropriately. A linking element may contain behavior attribute. XML:ACTUATE, which describes when an XML link should be activated. Valid values for XLINK:ACTUATE includes a) OnLoad: Tells the XML application to traverse the link immediately as soon as it loads the link source document. b) OnRequest: Tells the XML application to traverse the link on after the user requests link activation. c) Undefined: Tells the XML application that link activation must be performed by application specific means. XLINK:SHOW describes the way an XML link should appear when it is activated. Valid values for XLINK:SHOW attribute includes a) New: Tells the XML application to open the link in a new window frame. b) Replace: Tells the XML application to replace the current window frame with the activated link. c) Embed: Tells the XML application to embed the activated link in the current window. d) Undefined: Tells the XML application that the link display must be performed by application specific-means. X-POINTER: The XML pointer language defines the addressing scheme for the individual parts of an XML document. It can be used by any application that needs to identify a part or location of an XML document. X-pointer proposes to define many more relationships other than parent and child, can also be used to specify relationships between elements that are siblings- the next sibling or the previous sibling XML DOCUMENT OBJECT MODEL (DOM): XML DOM defines a logical-tree for an XML document. The basic building block of the tree is node. Nodes are generic containers that hold information about the elements, attributes, content, comments, and processing instructions that are stored in an XML document. W3Cs DOM offers programmers a platform and language neutral program interface which will make programming reliably across platforms. Node objects have a set of methods and properties and well-defined characteristics. Some of these characteristics are: Nodes have a single parent node, a parent node being a node directly above it. The only nodes that do not have a parent is the Document root, as it is the top-level node and contains the document itself. Most nodes can have multiple child nodes, which are nodes directly below it. Nodes that are at the same level, are siblings The DOM is a programming interface for HTML and XML documents. It defines the way a document can be accessed and manipulated. Using a DOM, a programmer can create a document, navigates its structure, and add, modify, or delete its elements. The DOM expresses the structure of an HTML document. It describes the document structure in terms of The type of tags on the page The number of tags on the page The order of these tags on the page The properties of these tags on the page The presentational nature of each element
DOM creates an object for each element on the page. These objects have child objects and properties. The child objects can further have child objects and properties. This makes a hierarchy of objects. The WINDOW object is top most object in the hierarchy. The DOCUMENT object, which is a child object of WINDOW object, represents the page loaded in the browser window. A part from objects, the object model contains collections. The collection is an array holding one or more objects. XML QUERY LANGAUGE: XML can represent files, graphics, web services. As developers store more and more information in XML format, they also have an increasing need to be able to search and update XML documents. XML has the ability to describe virtually any data source, its query language needs to have the expressive power query language for unlike data source.
15
Web Programming
The World Wide Web Consortium (W3C) began working on the problem. The result of that effort is the XQuery Language. X-Query Language is a hybrid, a powerful language with grammar similar to SQL, but more widely applicable. XQuery Language provides information, integration, and transformation capabilities. An X-Query Language implementation can search multiple back-end systems and combine results, effectively integrating multiple sources of information. X-Query Language can also transform the content and structure of XML documents. We can use X-Query Language expressions such as element and attribute constructs to express the structure of the result document.
16