WP - I Unit-V IT

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Unit-V

XML AND WEB SERVICES


Xml – Introduction-Form Navigation-XML Documents- XSL – XSLT- Web services-UDDI-
WSDL-Java web services – Web resources.

XML:
XML stands for Extensible Markup Language. It is a text-based markup language derived
from Standard Generalized Markup Language (SGML).
XML tags identify the data and are used to store and organize the data, rather than
specifying how to display it like HTML tags, which are used to display the data. XML is not
going to replace HTML in the near future, but it introduces new possibilities by adopting
many successful features of HTML.
There are three important characteristics of XML that make it useful in a variety of systems
and solutions −
• XML is extensible − XML allows you to create your own self-descriptive tags, or
language, that suits your application.
• XML carries the data, does not present it − XML allows you to store the data
irrespective of how it will be presented.
• XML is a public standard − XML was developed by an organization called the
World Wide Web Consortium (W3C) and is available as an open standard.
XML Usage
A short list of XML usage says it all −
• XML can work behind the scene to simplify the creation of HTML documents for
large web sites.
• XML can be used to exchange the information between organizations and systems.
• XML can be used for offloading and reloading of databases.
• XML can be used to store and arrange the data, which can customize your data
handling needs.
• XML can easily be merged with style sheets to create almost any desired output.
• Virtually, any type of data can be expressed as an XML document.
What is Markup?
XML is a markup language that defines set of rules for encoding documents in a format that
is both human-readable and machine-readable. So what exactly is a markup
language? Markup is information added to a document that enhances its meaning in certain
ways, in that it identifies the parts and how they relate to each other. More specifically, a
markup language is a set of symbols that can be placed in the text of a document to
demarcate and label the parts of that document.
Following example shows how XML markup looks, when embedded in a piece of text −
<message>
<text>Hello, world!</text>
</message>
This snippet includes the markup symbols, or the tags such as <message>...</message> and
<text>... </text>. The tags <message> and </message> mark the start and the end of the
XML code fragment. The tags <text> and </text> surround the text Hello, world!.
Is XML a Programming Language?
A programming language consists of grammar rules and its own vocabulary which is used to
create computer programs. These programs instruct the computer to perform specific tasks.
XML does not qualify to be a programming language as it does not perform any
computation or algorithms. It is usually stored in a simple text file and is processed by
special software that is capable of interpreting XML.
Form Navigation:

Navigating DOM Nodes


Accessing nodes in the node tree via the relationship between nodes, is often called
"navigating nodes".
In the XML DOM, node relationships are defined as properties to the nodes:
• parentNode
• childNodes
• firstChild
• lastChild
• nextSibling
• previousSibling
The following image illustrates a part of the node tree and the relationship between nodes
in books.xml:

DOM - Parent Node


All nodes have exactly one parent node. The following code navigates to the parent node of
<book>:
Example
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("book")[0];
document.getElementById("demo").innerHTML = x.parentNode.nodeName;
}
Avoid Empty Text Nodes
Firefox, and some other browsers, will treat empty white-spaces or new lines as text nodes,
Internet Explorer will not.
This causes a problem when using the properties: firstChild, lastChild, nextSibling,
previousSibling.
To avoid navigating to empty text nodes (spaces and new-line characters between element
nodes), we use a function that checks the node type:
function get_nextSibling(n) {
var y = n.nextSibling;
while (y.nodeType! = 1) {
y = y.nextSibling;
}
return y;
}
The function above allows you to use get_nextSibling(node) instead of the
property node.nextSibling.
Code explained:
Element nodes are type 1. If the sibling node is not an element node, it moves to the next
nodes until an element node is found. This way, the result will be the same in both Internet
Explorer and Firefox.

Get the First Child Element


The following code displays the first element node of the first <book>:
Example
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();

function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = get_firstChild(xmlDoc.getElementsByTagName("book")[0]);
document.getElementById("demo").innerHTML = x.nodeName;
}

//check if the first node is an element node


function get_firstChild(n) {
var y = n.firstChild;
while (y.nodeType != 1) {
y = y.nextSibling;
}
return y;
}
</script>
</body>
</html>
Output:
title
XML Documents:

An XML document is a basic unit of XML information composed of elements and other
markup in an orderly package. An XML document can contains wide variety of data. For
example, database of numbers, numbers representing molecular structure or a mathematical
equation.
XML Document Example
A simple document is shown in the following example −
<?xml version = "1.0"?>
<contact-info>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</contact-info>
The following image depicts the parts of XML document.

Document Prolog Section


Document Prolog comes at the top of the document, before the root element. This section
contains −
• XML declaration
• Document type declaration
You can learn more about XML declaration in this chapter − XML Declaration
Document Elements Section
Document Elements are the building blocks of XML. These divide the document into a
hierarchy of sections, each serving a specific purpose. You can separate a document into
multiple sections so that they can be rendered differently, or used by a search engine. The
elements can be containers, with a combination of text and other elements.
XSLT:
XSL (eXtensible Stylesheet Language) is a styling language for XML.
XSLT stands for XSL Transformations.
This tutorial will teach you how to use XSLT to transform XML documents into other
formats (like transforming XML into HTML).

Online XSLT Editor


With our online editor, you can edit XML and XSLT code, and click on a button to view the
result.
XSLT Example
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
What You Should Already Know
Before you continue you should have a basic understanding of the following:
• HTML
• XML
If you want to study these subjects first, find the tutorials on our Home page.
XSLT References
XSLT Elements
Description of all the XSLT elements from the W3C Recommendation, and information
about browser support.
XSLT, XPath, and XQuery Functions
XSLT 2.0, XPath 2.0, and XQuery 1.0, share the same functions library. There are over 100
built-in functions. There are functions for string values, numeric values, date and time
comparison, node and QName manipulation, sequence manipulation, and more.

Web Services:
Web services are web application components.
Web services can be published, found, and used on the Web.
This tutorial introduces WSDL, SOAP, RDF, and RSS.

WSDL
• WSDL stands for Web Services Description Language
• WSDL is an XML-based language for describing Web services.
• WSDL is a W3C recommendation
SOAP
• SOAP stands for Simple Object Access Protocol
• SOAP is an XML based protocol for accessing Web Services.
• SOAP is based on XML
• SOAP is a W3C recommendation

RDF
• RDF stands for Resource Description Framework
• RDF is a framework for describing resources on the web
• RDF is written in XML
• RDF is a W3C Recommendation

RSS
• RSS stands for Really Simple Syndication
• RSS allows you to syndicate your site content
• RSS defines an easy way to share and view headlines and content
• RSS files can be automatically updated
• RSS allows personalized views for different sites
• RSS is written in XML

What You Should Already Know


Before you study web services you should have a basic understanding of XML and XML
Namespaces.
If you want to study these subjects first, please read our XML Tutorial.
Web Services
• Web services are application components
• Web services communicate using open protocols
• Web services are self-contained and self-describing
• Web services can be discovered using UDDI
• Web services can be used by other applications
• HTTP and XML is the basis for Web services

Interoperability has Highest Priority


When all major platforms could access the Web using Web browsers, different platforms
couldn't interact. For these platforms to work together, Web-applications were developed.
Web-applications are simply applications that run on the web. These are built around the
Web browser standards and can be used by any browser on any platform.
Web Services take Web-applications to the Next Level
By using Web services, your application can publish its function or message to the rest of the
world.
Web services use XML to code and to decode data, and SOAP to transport it (using open
protocols).
With Web services, your accounting department's Win 2k server's billing system can connect
with your IT supplier's UNIX server.
Web Services have Two Types of Uses
Reusable application-components.
There are things applications need very often. So why make these over and over again?
Web services can offer application-components like: currency conversion, weather reports, or
even language translation as services.
Connect existing software.
Web services can help to solve the interoperability problem by giving different applications a
way to link their data.
With Web services you can exchange data between different applications and different
platforms.
Any application can have a Web Service component.
Web Services can be created regardless of programming language.

A Web Service Example


In the following example we will use ASP.NET to create a simple Web Service that converts
the temperature from Fahrenheit to Celsius, and vice versa:
<%@ WebService Language="VBScript" Class="TempConvert" %>

Imports System
Imports System.Web.Services

Public Class TempConvert :Inherits WebService

<WebMethod()> Public Function FahrenheitToCelsius(ByVal Fahrenheit As String) As


String
dim fahr
fahr=trim(replace(Fahrenheit,",","."))
if fahr="" or IsNumeric(fahr)=false then return "Error"
return ((((fahr) - 32) / 9) * 5)
end function

<WebMethod()> Public Function CelsiusToFahrenheit(ByVal Celsius As String) As String


dim cel
cel=trim(replace(Celsius,",","."))
if cel="" or IsNumeric(cel)=false then return "Error"
return ((((cel) * 9) / 5) + 32)
end function

end class
This document is saved as an .asmx file. This is the ASP.NET file extension for XML Web
Services.

Example Explained
Note: To run this example, you will need a .NET server.
The first line in the example states that this is a Web Service, written in VBScript, and has the
class name "TempConvert":
<%@ WebService Language="VBScript" Class="TempConvert" %>
The next lines import the namespace "System.Web.Services" from the .NET framework:
Imports System
Imports System.Web.Services
The next line defines that the "TempConvert" class is a WebService class type:
Public Class TempConvert :Inherits WebService
The next steps are basic VB programming. This application has two functions. One to convert
from Fahrenheit to Celsius, and one to convert from Celsius to Fahrenheit.
The only difference from a normal application is that this function is defined as a
"WebMethod()".
Use "WebMethod()" to convert the functions in your application into web services:
<WebMethod()> Public Function FahrenheitToCelsius(ByVal Fahrenheit As String) As
String
dim fahr
fahr=trim(replace(Fahrenheit,",","."))
if fahr="" or IsNumeric(fahr)=false then return "Error"
return ((((fahr) - 32) / 9) * 5)
end function

<WebMethod()> Public Function CelsiusToFahrenheit(ByVal Celsius As String) As String


dim cel
cel=trim(replace(Celsius,",","."))
if cel="" or IsNumeric(cel)=false then return "Error"
return ((((cel) * 9) / 5) + 32)
end function
Then, end the class:
end class
Publish the .asmx file on a server with .NET support, and you will have your first working
Web Service.

Put the Web Service on Your Web Site


Using a form and the HTTP POST method, you can put the web service on your site, like
this:
Fahrenheit to Celsius: Submit

Celsius to Fahrenheit: Submit

How To Do It
Here is the code to add the Web Service to a web page:
<form action='tempconvert.asmx/FahrenheitToCelsius'
method="post" target="_blank">
<table>
<tr>
<td>Fahrenheit to Celsius:</td>
<td>
<input class="frmInput" type="text" size="30" name="Fahrenheit">
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input type="submit" value="Submit" class="button">
</td>
</tr>
</table>
</form>

<form action='tempconvert.asmx/CelsiusToFahrenheit'
method="post" target="_blank">
<table>
<tr>
<td>Celsius to Fahrenheit:</td>
<td>
<input class="frmInput" type="text" size="30" name="Celsius">
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input type="submit" value="Submit" class="button">
</td>
</tr>
</table>
</form>

UDDI:
UDDI is an XML-based standard for describing, publishing, and finding web services.
• UDDI stands for Universal Description, Discovery, and Integration.
• UDDI is a specification for a distributed registry of web services.
• UDDI is a platform-independent, open framework.
• UDDI can communicate via SOAP, CORBA, Java RMI Protocol.
• UDDI uses Web Service Definition Language(WSDL) to describe interfaces to web
services.
• UDDI is seen with SOAP and WSDL as one of the three foundation standards of web
services.
• UDDI is an open industry initiative, enabling businesses to discover each other and
define how they interact over the Internet.
UDDI has two sections −
• A registry of all web service's metadata, including a pointer to the WSDL description
of a service.
• A set of WSDL port type definitions for manipulating and searching that registry.
History of UDDI
• UDDI 1.0 was originally announced by Microsoft, IBM, and Ariba in September
2000.
• Since the initial announcement, the UDDI initiative has grown to include more than
300 companies including Dell, Fujitsu, HP, Hitachi, IBM, Intel, Microsoft, Oracle,
SAP, and Sun.
• In May 2001, Microsoft and IBM launched the first UDDI operator sites and turned
the UDDI registry live.
• In June 2001, UDDI announced Version 2.0.
• As the time of writing this tutorial, Microsoft and IBM sites had implemented the 1.0
specification and were planning 2.0 support in the near future.
• Currently UDDI is sponsored by OASIS.
Partner Interface Processes
Partner Interface Processes (PIPs) are XML based interfaces that enable two trading partners
to exchange data. Dozens of PIPs already exist. Some of them are listed here −
• PIP2A2 − Enables a partner to query another for product information.
• PIP3A2 − Enables a partner to query the price and availability of specific products.
• PIP3A4 − Enables a partner to submit an electronic purchase order and receive
acknowledgment of the order.
• PIP3A3 − Enables a partner to transfer the contents of an electronic shopping cart.
• PIP3B4 − Enables a partner to query the status of a specific shipment.
Private UDDI Registries
As an alternative to using the public federated network of UDDI registries available on the
Internet, companies or industry groups may choose to implement their own private UDDI
registries.
These exclusive services are designed for the sole purpose of allowing members of the
company or of the industry group to share and advertise services amongst themselves.
Regardless of whether the UDDI registry is a part of the global federated network or a
privately owned and operated registry, the one thing that ties them all together is a common
web services API for publishing and locating businesses and services advertised within the
UDDI registry.
WSDL:

WSDL stands for Web Services Description Language. It is the standard format for
describing a web service. WSDL was developed jointly by Microsoft and IBM.
Features of WSDL
• WSDL is an XML-based protocol for information exchange in decentralized and
distributed environments.
• WSDL definitions describe how to access a web service and what operations it will
perform.
• WSDL is a language for describing how to interface with XML-based services.
• WSDL is an integral part of Universal Description, Discovery, and Integration
(UDDI), an XML-based worldwide business registry.
• WSDL is the language that UDDI uses.
• WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'.
WSDL Usage
WSDL is often used in combination with SOAP and XML Schema to provide web services
over the Internet. A client program connecting to a web service can read the WSDL to
determine what functions are available on the server. Any special datatypes used are
embedded in the WSDL file in the form of XML Schema. The client can then use SOAP to
actually call one of the functions listed in the WSDL.
History of WSDL
WSDL 1.1 was submitted as a W3C Note by Ariba, IBM, and Microsoft for describing
services for the W3C XML Activity on XML Protocols in March 2001.
WSDL 1.1 has not been endorsed by the World Wide Web Consortium (W3C), however it
has just released a draft for version 2.0 that will be a recommendation (an official standard),
and thus endorsed by the W3C.

Java Web Services:


Different books and different organizations provide different definitions to Web Services.
Some of them are listed here.
• A web service is any piece of software that makes itself available over the internet
and uses a standardized XML messaging system. XML is used to encode all
communications to a web service. For example, a client invokes a web service by
sending an XML message, then waits for a corresponding XML response. As all
communication is in XML, web services are not tied to any one operating system or
programming language—Java can talk with Perl; Windows applications can talk
with Unix applications.
• Web services are self-contained, modular, distributed, dynamic applications that can
be described, published, located, or invoked over the network to create products,
processes, and supply chains. These applications can be local, distributed, or web-
based. Web services are built on top of open standards such as TCP/IP, HTTP, Java,
HTML, and XML.
• Web services are XML-based information exchange systems that use the Internet for
direct application-to-application interaction. These systems can include programs,
objects, messages, or documents.
• A web service is a collection of open protocols and standards used for exchanging
data between applications or systems. Software applications written in various
programming languages and running on various platforms can use web services to
exchange data over computer networks like the Internet in a manner similar to inter-
process communication on a single computer. This interoperability (e.g., between
Java and Python, or Windows and Linux applications) is due to the use of open
standards.
To summarize, a complete web service is, therefore, any service that −
• Is available over the Internet or private (intranet) networks
• Uses a standardized XML messaging system
• Is not tied to any one operating system or programming language
• Is self-describing via a common XML grammar
• Is discoverable via a simple find mechanism
Components of Web Services
The basic web services platform is XML + HTTP. All the standard web services work using
the following components −
• SOAP (Simple Object Access Protocol)
• UDDI (Universal Description, Discovery and Integration)
• WSDL (Web Services Description Language)
All these components have been discussed in the Web Services Architecture chapter.
How Does a Web Service Work?
A web service enables communication among various applications by using open standards
such as HTML, XML, WSDL, and SOAP. A web service takes the help of −
• XML to tag the data
• SOAP to transfer a message
• WSDL to describe the availability of service.
You can build a Java-based web service on Solaris that is accessible from your Visual Basic
program that runs on Windows.
You can also use C# to build new web services on Windows that can be invoked from your
web application that is based on JavaServer Pages (JSP) and runs on Linux.
Example
Consider a simple account-management and order processing system. The accounting
personnel use a client application built with Visual Basic or JSP to create new accounts and
enter new customer orders.
The processing logic for this system is written in Java and resides on a Solaris machine,
which also interacts with a database to store information.
The steps to perform this operation are as follows −
•The client program bundles the account registration information into a SOAP
message.
• This SOAP message is sent to the web service as the body of an HTTP POST request.
• The web service unpacks the SOAP request and converts it into a command that the
application can understand.
• The application processes the information as required and responds with a new
unique account number for that customer.
• Next, the web service packages the response into another SOAP message, which it
sends back to the client program in response to its HTTP request.
• The client program unpacks the SOAP message to obtain the results of the account
registration process.
Web Resources:

Different books and different organizations provide different definitions to Web Services.
Some of them are listed here.
• A web service is any piece of software that makes itself available over the internet
and uses a standardized XML messaging system. XML is used to encode all
communications to a web service. For example, a client invokes a web service by
sending an XML message, then waits for a corresponding XML response. As all
communication is in XML, web services are not tied to any one operating system or
programming language—Java can talk with Perl; Windows applications can talk
with Unix applications.
• Web services are self-contained, modular, distributed, dynamic applications that can
be described, published, located, or invoked over the network to create products,
processes, and supply chains. These applications can be local, distributed, or web-
based. Web services are built on top of open standards such as TCP/IP, HTTP, Java,
HTML, and XML.
• Web services are XML-based information exchange systems that use the Internet for
direct application-to-application interaction. These systems can include programs,
objects, messages, or documents.
• A web service is a collection of open protocols and standards used for exchanging
data between applications or systems. Software applications written in various
programming languages and running on various platforms can use web services to
exchange data over computer networks like the Internet in a manner similar to inter-
process communication on a single computer. This interoperability (e.g., between
Java and Python, or Windows and Linux applications) is due to the use of open
standards.
To summarize, a complete web service is, therefore, any service that −
• Is available over the Internet or private (intranet) networks
• Uses a standardized XML messaging system
• Is not tied to any one operating system or programming language
• Is self-describing via a common XML grammar
• Is discoverable via a simple find mechanism
Components of Web Services
The basic web services platform is XML + HTTP. All the standard web services work using
the following components −
• SOAP (Simple Object Access Protocol)
• UDDI (Universal Description, Discovery and Integration)
• WSDL (Web Services Description Language)
All these components have been discussed in the Web Services Architecture chapter.
How Does a Web Service Work?
A web service enables communication among various applications by using open standards
such as HTML, XML, WSDL, and SOAP. A web service takes the help of −
• XML to tag the data
• SOAP to transfer a message
• WSDL to describe the availability of service.
You can build a Java-based web service on Solaris that is accessible from your Visual Basic
program that runs on Windows.
You can also use C# to build new web services on Windows that can be invoked from your
web application that is based on JavaServer Pages (JSP) and runs on Linux.
Example
Consider a simple account-management and order processing system. The accounting
personnel use a client application built with Visual Basic or JSP to create new accounts and
enter new customer orders.
The processing logic for this system is written in Java and resides on a Solaris machine,
which also interacts with a database to store information.
The steps to perform this operation are as follows −
• The client program bundles the account registration information into a SOAP
message.
• This SOAP message is sent to the web service as the body of an HTTP POST request.
• The web service unpacks the SOAP request and converts it into a command that the
application can understand.
• The application processes the information as required and responds with a new
unique account number for that customer.
• Next, the web service packages the response into another SOAP message, which it
sends back to the client program in response to its HTTP request.
• The client program unpacks the SOAP message to obtain the results of the account
registration process.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy