Вы находитесь на странице: 1из 14

What is JavaScript?

JavaScript is scripting language used for client side scripting.JavaScript developed by Netscape in 1995 as a method for validating forms and providing interactive content to web site. Microsoft and Netscape introduced JavaScript support in their browsers. JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary Everyone can use JavaScript without purchasing a license. JavaScript is an object-oriented language with prototypal inheritance. The language supports several built-in objects, and programmers can create or delete their own objects. Prototypal inheritance makes JavaScript very different from other popular programming languages such as C++, C#, or Java featuring classes and classical inheritance. JavaScript does not have classes in the C++ or Java sense. In JavaScript, objects can inherit properties directly from each other, forming the object prototype chain. What is JavaScript and how is it different from Java Technology? The JavaScript programming language, developed by Netscape, Inc., is not part of the Java platform. JavaScript, does not create applets or stand-alone applications. In its most common form today, JavaScript resides inside HTML documents, and can provide levels of interactivity to web pages that are not achievable with simple HTML. Listed are key differences between the Java and JavaScript. Java is an OOP programming language while Java Script is an OOP scripting language. Java creates applications that run in a virtual machine or browser while JavaScript code is run on a browser only. Java code needs to be compiled while JavaScript code are all in text. They require different plug-ins. JAVASCRIPT: ADVANTAGES JavaScript is one of the most simple, versatile and effective languages used to extend functionality in websites. Uses range from on screen visual effects to processing and calculating data on web pages with ease as well as extended functionality to websites using third party scripts among several other handy features. Advantages Javascript is executed on the client side This means that the code is executed on the user's processor instead of the web server thus saving bandwidth and strain on the web server. JavaScript is a relatively easy language

The JavaScript language is relatively easy to learn and comprises of syntax that is close to English. It uses the DOM model that provides plenty of prewritten functionality to the various objects on pages making it a breeze to develop a script to solve a custom purpose.

JavaScript is relatively fast to the end user As the code is executed on the user's computer, results and processing is completed almost instantly depending on the task (tasks in JavaScript on web pages are usually simple so as to prevent being a memory hog) as it does not need to be processed in the site's web server and sent back to the user consuming local as well as server bandwidth. Extended functionality to web pages Third party add-ons like Grease monkey enable JavaScript developers to write snippets of JavaScript which can execute on desired web pages to extend its functionality. If you use a website and require a certain feature to be included, you can write it yourself and use an add-on like Grease monkey to implement it on the web page. JavaScript is usually used for the following purposes: Customizing a page based on the user's browser version Providing visual feedback to user actions Checking for mistakes in forms before they are submitted You could make a page which uses a script that allows a message to appear in the status bar. Or, a message can be made to appear whenever the mouse runs over a certain link. It is very simple, but you have to be careful in writing the scripts because JavaScript is case sensitive. JavaScript Events Handling This is a very vital concept of JavaScript because without events there would be no code. Event handling is the execution of code for the users reaction. In other words, when a user performs some action, the associated event fires or executes. For example, if a programmer want a piece of code to execute when a user presses a button, then the code is placed in the onclick event of the button, executing the code when the user clicks that button. In addition, there are events in JavaScript that are automatically fired without the intervention of the user. The load event fires when the page loads. Thus, there are various scenarios for firing events such as: When the user performs some action based on which event fires When the page load event fires When some fields change, the associated events fire. There are numerous events in JavaScript, some of which are listed below. A particular object has numerous events associated with it, depending on the action taken by the user. For example, the object mouse has numerous events associated with it which depend on the users actions. Attribute Tag Description

onkeydown onkeypress onkeyup onload onmousedown onmousemove onmouseout onmouseover

<body> Form elements <body> Form elements <body> Form elements <body> Most elements Most elements Most elements Most elements

A key is pressed down A key is pressed down and released A key is released The document is finished loading The user clicks the left mouse button The user moves the mouse cursor within the element The mouse cursor is moved away from being over the element The mouse cursor is moved over the element

onmouseup onreset onselect onsubmit onunload onblur

Most elements <form> <input> <textarea> <form> <body> <a> <button> <input> <textarea>

The left mouse button is unclicked The reset button is clicked The mouse cursor is moved over the element The submit button is pressed The user exits the document The link loses the input focus The button loses the input focus The input element loses the input focus The text area loses the input focus The select loses the input focus The input element is changed and loses the input focus The text area is changed and loses the input focus The selection element is changed and loses the input focus The user double clicks the left mouse button The link acquires the input focus The input element receives the input focus The text area receives the input focus The select receives the input focus

onchange

<select> <input> <textarea> <select>

ondbclick onfocus

Most elements <a> <input> <textarea> <select>

EXTENSIBLE MARKUP LANGUAGE (XML)

What is XML?
Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. XML is a markup language much like HTML. XML was designed to carry data, not to display data. XML tags are not predefined. You must define your own tags. XML is designed to be self-descriptive.

The Difference between XML and HTML


XML is not a replacement for HTML. XML and HTML were designed with different goals: XML was designed to transport and store data, with focus on what data is HTML was designed to display data, with focus on how data looks HTML is about displaying information, while XML is about carrying information. XML is a software- and hardware-independent tool for carrying information.

Features of XML
Main features of XML: XML files are text files, which can be managed by any text editor. XML is very simple, because it has less than 10 syntax rules.

XML is extensible, because it only specifies the structural rules of tags. No specification on tags them self. XML provides a basic syntax that can be used to share information between different kinds of computers, different applications, and different organizations. XML data is stored in plain text format. This software- and hardwareindependent way of storing data allows different incompatible systems to share data without needing to pass them through many layers of conversion. This also makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without losing any data. With XML, your data can be available to all kinds of "reading machines" It supports Unicode, allowing almost any information in any written human language to be communicated. It can represent common computer science data structures: records, lists and trees. Its self-documenting format describes structure and field names as well as specific values. The strict syntax and parsing requirements make the necessary parsing algorithms extremely simple, efficient, and consistent. Content-based XML markup enhances searchability, making it possible for agents and search engines to categorize data instead of wasting processing power on context-based full-text searches. XML is heavily used as a format for document storage and processing, both online and offline. It can be updated incrementally.

Document Type Definition:


A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes.

It is a set of structural rules called declarations, which specify a set of elements that can appear in the document as well as how and where these elements appear. A DTD can be declared inline inside an XML document, or as an external reference. Internal DTD Declaration If the DTD is declared inside the XML file, it should be wrapped in a DOCTYPE definition with the following syntax: <!DOCTYPE root-element [element-declarations]> External DTD Declaration If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following syntax: <!DOCTYPE root-element SYSTEM "filename">

Why Use a DTD?


With a DTD, each of your XML files can carry a description of its own format. With a DTD, independent groups of people can agree to use a standard DTD for interchanging data. Your application can use a standard DTD to verify that the data you receive from the outside world is valid. You can also use a DTD to verify your own data.

Namespaces
An XML Namespace is a collection of element and attribute names used in XML documents. The name of a namespace usually has the form of a uniform resource identifier (URI). A namespace for the elements and attributes of the hierarchy rooted

at a particular element is declared as the value of the attribute xmlns. The form a namespace declaration for an element follows: <element_name xmlns[:prefix]=URI> Square baracket indicate that what is within them is optional. The prefix is the name that must be attached to the names in the declared namespace. A prefix is used for two reasons First, the URI is too long to be typed on every occurrence of every name from the namespace. Second, a URI includes characters that are illegal in XML. The XHTML documents declare the xmlns namespace on the root element: <html xmlns=http://www.w3.org/1999/xhtml> This declares the default namespace, from which names may appear without prefixes.

Schemas
XML Schema defines the elements , attributes, elements having child elements, order of child elements. It also defines fixed and default values of elements and attributes. XML Schema also allows the developer to use data types. Schema Fundamentals Schemas have two primary purposes First, a schema specifies the structure of its instance XML documents, including which elements and attributes may appear in the instance document, as well as when and where how often they appear. Second, a schema specifies the data type of every element and attribute of its instance XML document. XML schemas are namespace sentric. Every schema has schema as its root element. The schema element specifies the namespace for the schema of schemas from which the schemas elements and attributes will be drawn. It often also specifies a prefix Xmlns:xsd=http://www.w3.org/2001/XMLSchema

This provides the prefix xsd for the names from the namespace for the schema of schemas.

XSLT
XSL stands for Extensible Stylesheet Language, and is a style sheet language for XML documents. XSLT stands for XSL Transformations. XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more. A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree.

XSLT Uses XPath XSLT uses XPath to find information in an XML document. XPath is used to navigate through elements and attributes in XML documents. How does it work? In the transformation process, XSLT uses XPath to define parts of the source document that should match one or more predefined templates. When a match is found, XSLT will transform the matching part of the source document into the result document. XSLT is actually a functional style programming language. Included in XSLT are functions, parameters, names to which values can be bound, selection constructs, and conditional expressions for multiple selection. The syntactic structure of XSLT is XML, so each statement is specified with an element. Applications often use XSLT to convert XML data into HTML or XHTML documents for display as a web page. The

transformation may happen dynamically either on a client or on a server, or it may be done as part of the publishing process. XSLT processors take as input an XML document and an XSLT document.The XSLT is the program to be executed. XML document is the input data to the program. Parts of XML document are selected, modified and merged with parts of the XSLT document to form a new document which is called as XSL document.