Showing posts with label task3. Show all posts
Showing posts with label task3. Show all posts

Thursday, 17 November 2011

What is AJAX and what are its purposes?


AJAX stands for Asynchronous JavaScript and XML, and is a group of technologies used to create dynamic web pages. The main objective of AJAX is to allow pages to have their content modified, without having to re-download the whole page again.

Before AJAX become widespread, most websites relied mostly on separate HTML files for displaying even dynamic content – such as constantly changing game scores, displayed by a betting company’s website. This has proven troublesome both for the company, because each time the information to be displayed changed, the server had to send a new, updated HTML file – which was costly due to heavy bandwidth usage. It was also inconvenient for the users, since the whole page had to be reloaded.

Therefore, the need for methods such as AJAX became apparent. It was first implemented by Microsoft’s Internet Explorer, taking the form of iframe elements – which allowed only for parts of a webpage to be updated by the server. This technology evolved into the XMLHttpRequest JavaScript object, which forms the backbone of current AJAX technologies and is supported by all modern browsers.

However, wide adoption by browsers did not translate into wide adoption, and such technologies remained uncommon until their successful employment by Microsoft and Google in large-scale applications such as Outlook Web Access and Gmail. This proved the value and usefulness of AJAX technologies, and spurred their adoption for mainstream web development.

Taking a website which displays football scores of on-going games, without AJAX the users would have to re-download the whole HTML file in order to notice any changes in scores. But it would be much better to be able to re-download just the XML file containing the scores, and update the HTML file accordingly, and AJAX makes that possible.

An XMLHttpRequest object would be created from the JavaScript file, and a function would be called when the object’s readyState property changes ( via the xhr.onreadystatechange function, assuming the XMLHttpRequest object is named xhr. ) The function would parse the retrieved data, and update the HTML code accordingly, without having to re-download all of the HTML code from the server.

Tuesday, 15 November 2011

What are the differences between elements and attributes and what are their different uses?


As defined in the XML standard, a well-formed XML document must contain one or more elements; an element is has the form STag content ETag - it consists of content, enclosed between a start tag and an end tag. An XML document will not be
valid if the name of the start tag does not match, case-sensitively, the end tag.

To ensure validity of the document, all contained elements must be valid – it must respect XML syntax, and the DTD or XML Schema, if it has one. If the element is defined empty, then it must not have any content, not even comments or whitespace. Elements are used for the semantic markup of the XML document.

An element can have zero, one or more attributes, which are declared inside an attribute-list declaration and are used to describe various properties of the element they are attached to. Attribute-list declarations can also be used to provide default values for attributes. To ensure well-formedness, an attribute must not appear more than one time in the same tag. Another well-formedness constraint is that attribute values must not contain the ‘<’ character, and that values must be enclosed in quotes.

The exact meaning of an attribute, and how to interpret it’s value, depends on the particular XML implementation. For example, XHTML supports the “id” attribute – which is meant to have as a value a document-wide unique id, to be used for styling or layout. Other types of XML documents might also declare “id” attribute, but it might have a different meaning, and therefore no assumptions should be made.

Monday, 14 November 2011

What is the importance of the first line of an XML document?

The first line of an XML document must not be blank, since the document will fail the well-formedness test, and cannot be a valid XML document. As described in the standard, an XML document should begin with an XML declaration which specifies the version of XML being used. (http://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd )

However, a document not declaring the XML version on the first line can still pass the well-formedness test, but it cannot be a valid document. If the first line is blank, it cannot be well-formed, nor valid.

For example, the following is a well-formed XML document, but not valid:

<?xml version="1.0"?>
<foo>This is the content of the foo element</foo> 

This can be tested in an XML validator; for example, the one found at http://www.validome.org/xml/validate/


As visible from above, the document is not valid because nowhere is the <foo> element declared. However, if we only test for well-formedness:



So summarize, the first line of an XML file should be used to specify the version of XML used; but it can also be any element, as long as it is not blank. However, a document without the declaration of the version of XML used cannot be valid – it can be well-formed, assuming XML syntax is respected throughout the file.

How can an XML document be best presented?


An XML document can be presented by styling it with CSS, but XSLT ( Extensible Stylesheet Language Transformation ) is preferred. XSLT is a language which itself is XML, and can be used for a number of transformations of XML documents.

One common application of XSLT is for transforming an XML document into HTML, which will be presented to the user. The advantages of this approach are obvious; it allows a straightforward way of presenting content, as opposed to the more traditional way of storing data in a database, extracting it, and generating HTML from it. Using XSLT represents a simpler solution, and therefore less room for errors.

XSLT can also be used to target various displays, or can be used in combination with XSL Formatting Objects to generate files in a variety of formats, including PDF documents and PNG images. One of the main advantages of using XSLT is that XSLT processors can be either client-side, or server-side.

The presentation of XML documents, transformed using XSLT is not limited to websites; XSLT transformations are supported by Windows XP ( via MSXML3 ) and the GNOME desktop environment for Linux. XSLT fully leverages the advantages offered by being written in XML – it is a widely available and versatile technology, that can be adapted to various purposes, and parsers are relatively easy to write because of the numerous existing applications.

Sunday, 13 November 2011

What is XML validation and what is the output?


XML validation is the process by which a document is checked to ensure the document is a well-formed XML document, and also that it’s structure corresponds to it’s declared Document Type Definition ( DTD ) or XML Schema. If a document is not well-formed, it cannot be valid.

An XML parser can be either validating or non-validating, depending on it’s ability to validate an XML document against a DTD or an XML Schema. A non-validating XML processor will only check for correct syntax, and interrupt parsing at the first encountered error. A validating parser will first perform the well-formedness test, and then proceed ( if the document is a well-formed XML document ) to check whether the contents match the description in the DTD/XMS. Unlike the well-formedness test, a validating parser is free to choose the course of action when validity errors are encountered; the parser can simply stop parsing and exit, or it could notify the user of the error and then continue parsing.

The output of an XML validator depends on the implementation; the XML standard allows for some flexibility in this regard. It would most likely consist of a list of errors encountered, such as the w3schools validator (http://www.w3schools.com/xml/xml_validator.asp ).

Saturday, 12 November 2011

What is XML well-formedness and how could you measure it?


If an XML document is well-formed, it conforms to the syntax rules, as defined in the XML standard. Unlike HTML, the XML standard is very strict, and does not tolerate errors such as the omission of a closing tag, or having different cases in the opening and closing tags; for example, the following is not a well-formed XML document:

1 <?xml version="1.0"?>
2 <person>
3     <name>John Smith</Name>
4 </person>

Although the “name” tag was closed, the closing tag tag should have the same casing as the opening tag, therefore this document is not a well-formed XML file. The line should be: <name>John Smith</name> to form a well-formed XML document.

Well-formedness also implies correct nesting; for example, the following code is not well-formed because the <surname> tag was opened before the <name> tag was closed, therefore the two tags overlap – which is not allowed in XML.
Wrong: 
<name>John<surname>Smith</name></surname>

Correct:
<name>John</name><surname>Smith</surname>

Another way in which documents can fail the well-formedness test is by not having a single root tag; in other words, all of the tags inside the document must reside inside a unique pair of opening and closing tags. But it doesn’t have to be the xml tag; it could be any tag ( with a valid name, of course ).

Well-formedness can be checked with special tools – for example, the w3scools validator (http://www.w3schools.com/xml/xml_validator.asp); but due to the strictness of the XML standard, the parser should abort at the first encountered error. Therefore, the number of errors is rarely important; what matters is whether the whole document is valid.