Web Technology

Batches: M.Tech. 2nd Semester B.Tech 6th Semester B.Tech. 8th Semester MCA 4th Semester B.Tech. Electronics 8th Semester

Mr. Debojit Boro Assistant Professor,Tezpur University,Napaam,Tezpur-784028

Topics for today XML HTTP Request XML Parser

Mr. Debojit Boro Assistant Professor,Tezpur University,Napaam,Tezpur-784028

XMLHttpRequest 

XMLHttpRequest is used to communicate with your server from inside a web page. Update a web page with new data without reloading the page Request and receive new data from a server after the page has loaded Communicate with a server in the background 

 

Creation of XMLHttpRequest 

var xmlhttp=new XMLHttpRequest() Or in IE 5 or 6 

var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

XML Parsing 

Two approaches for XML Parsing

SAX Approach

String of Elements

XML Doc Tree Like Structure

DOM Approach

XML Document

<bookstore> <book> <title>Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> </bookstore>

SAX (Simple API for XML) µll look like
StartElement:bookstore StartElement:book StartElement:title Characters: Everyday Italian EndElement:title

Sequential Approach(SAX) also know as Simple API for XML 
 

 

It is an incremental approach Signals the application program about the start and end of elements Deals with only single element at a time Considers data to be made up of string of elements It concentrate just on the current and not on the XML Document in totality

Document Object Model(DOM)   



This approach treats the XML Document as a tree like structure Loads the entire XML document into the memory Compiles the XML Doc into an internal tree Converts the elements and attributes into nodes of the tree

XML Parser    

The XML DOM contains methods (functions) to traverse XML trees, access, insert, and delete nodes. However, before an XML document can be accessed and manipulated, it must be loaded into an XML DOM object. An XML parser reads XML, and converts it into an XML DOM object that can be accessed with JavaScript. Most browsers have a built-in XML parser. 

                

<html> <body> <script type="text/javascript"> if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // for older IE 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","books.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; document.write("XML document loaded into an XML DOM Object."); </script> </body> </html>

Code for loading of XML Document

XML VS HTML 
 

  

XML and HTML are not alternative to each other They are complement to each other  HTML is for presentation  XML for meaningful encoding To display an XML document we have to transform to HTML XHTML is the XML version of HTML If we display raw XML document we may get only a tree view Tree View XML Example We can display an XML document with CSS Example with css We can also display by transforming XML to HTML by XSL

XML Transformation    



XML document can be transformed to another XML document or to HTML XML content needs to be transformed to HTML if we want the content to be displayed by the browser XSL (eXtensible Stylesheet Language) captures the rues of transformation XSL also follows XML syntax In the XML file include this reference
<?xml-stylesheet type="text/xsl" ref=³customer.xsl"?>

Classwork 

Create an XML document that describes your details in the following hierarchy LastName FirstName MiddleName Years Months Country State City Pin Country code Area code Phone number

Name

Age Address

Phone

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.