0% found this document useful (0 votes)
18 views

UNIT-5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

UNIT-5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 18

What is xml

o Xml (eXtensible Markup Language) is a mark up language.


o XML is designed to store and transport data.
o Xml was released in late 90’s. it was created to provide an easy to
use and store self describing data.
o XML became a W3C Recommendation on February 10, 1998.
o XML is not a replacement for HTML.
o XML is designed to be self-descriptive.
o XML is designed to carry data, not to display data.
o XML tags are not predefined. You must define your own tags.
o XML is platform independent and language independent.

What is mark-up language


A mark up language is a modern system for highlight or underline a
document.

Students often underline or highlight a passage to revise easily, same in


the sense of modern mark up language highlighting or underlining is
replaced by tags.

Why xml
Platform Independent and Language Independent: The main benefit
of xml is that you can use it to take data from a program like Microsoft
SQL, convert it into XML then share that XML with other programs and
platforms. You can communicate between two platforms which are
generally very difficult.

The main thing which makes XML truly powerful is its international acceptance.
Many corporation use XML interfaces for databases, programming, office
application mobile phones and more. It is due to its platform independent
feature.

Features and Advantages of XML


XML is widely used in the era of web development. It is also used to
simplify data storage and data sharing.

The main features or advantages of XML are given below.

1) XML separates data from HTML


If you need to display dynamic data in your HTML document, it will take a
lot of work to edit the HTML each time the data changes.

With XML, data can be stored in separate XML files. This way you can
focus on using HTML/CSS for display and layout, and be sure that changes
in the underlying data will not require any changes to the HTML.

2) XML simplifies data sharing


In the real world, computer systems and databases contain data in
incompatible formats.

XML data is stored in plain text format. This provides a software- and
hardware-independent way of storing data.

This makes it much easier to create data that can be shared by different
applications.

3) XML simplifies data transport


One of the most time-consuming challenges for developers is to exchange
data between incompatible systems over the Internet.

Exchanging data as XML greatly reduces this complexity, since the data
can be read by different incompatible applications.

4) XML simplifies Platform change


Upgrading to new systems (hardware or software platforms), is always
time consuming. Large amounts of data must be converted and
incompatible data is often lost.

XML data is stored in text format. This makes it easier to expand or


upgrade to new operating systems, new applications, or new browsers,
without losing data.

5) XML increases data availability


Different applications can access your data, not only in HTML pages, but
also from XML data sources.

With XML, your data can be available to all kinds of "reading machines"
(Handheld computers, voice machines, news feeds, etc), and make it
more available for blind people, or people with other disabilities.

6) XML can be used to create new internet languages


A lot of new Internet languages are created with XML.
o XHTML
o WSDL for describing available web services
o WAP and WML as markup languages for handheld devices
o RSS languages for news feeds
o RDF and OWL for describing resources and ontology
o SMIL for describing multimedia for the web

XML Example
XML documents create a hierarchical structure looks like a tree so it is
known as XML Tree that starts at "the root" and branches to "the leaves".

Example of XML Document


XML documents uses a self-describing and simple syntax:

<?xml version="1.0" encoding="ISO-8859-1"?>


<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

Form Navigation

Form navigation typically involves guiding users through a series of input fields
or screens in a structured manner.

<!-- Define your form navigation structure -->

<navigation>

This line marks the beginning of the XML document and indicates that we're
defining a navigation structure.

<!-- Define destinations/screens -->

<fragment
android:id="@+id/firstFragment"

android:name="com.example.FirstFragment"

android:label="First Fragment">

 android:id: Unique identifier for this fragment.

 android:name: Fully qualified class name of the fragment.

 android:label: Display label for this fragment (optional).

<action

android:id="@+id/action_firstFragment_to_secondFragment"

app:destination="@id/secondFragment" />

Within the first fragment, we define an action to navigate to the second fragment.

 android:id: Unique identifier for this action.

 app:destination: Specifies the destination fragment to navigate to, in this case, the second
fragment.

<!-- Define other actions if needed -->

</fragment>

<!-- Define other fragments and their navigation actions -->

<!-- Define the starting destination -->

<action

android:id="@+id/action_global_firstFragment"

app:destination="@id/firstFragment"

app:launchSingleTop="true"

app:popUpTo="@id/nav_graph"

app:popUpToInclusive="true"/>

 android:id: Unique identifier for this action.


 app:destination: Specifies the starting destination fragment.

 app:launchSingleTop: Indicates whether to launch the destination on the top of the current
task stack.

 app:popUpTo: Specifies the navigation destination to pop up to when this action is


executed.

 app:popUpToInclusive: Indicates whether the destination specified in app:popUpTo should


be included in the pop operation.

</navigation>

Marks the end of the navigation definition.

XML (eXtensible Markup Language) documents

XML (eXtensible Markup Language) documents are structured text files used for
storing and transporting data in a format that is both human-readable and
machine-readable

Elements:

XML documents are made up of elements, which are defined by a start tag,
content, and an end tag. For example:

<book>

<title>Harry Potter</title>

<author>J.K. Rowling</author>

</book>

Tags:

Tags are used to define elements. They are enclosed in angle brackets (< and
>). Tags can be opening (<tag>) or closing (</tag>).

Attributes:Elements can have attributes, which provide additional information


about an element. Attributes appear within the start tag of an element. For
example:

<book id="001">

<!-- Content here -->

</book>

Root Element:
Every XML document must have a single root element, which contains all other
elements.

Comments:

Comments in XML documents are enclosed within <!-- and -->. They are used to
add explanatory notes or annotations within the document.

Whitespace:

XML ignores whitespace between elements, except within text content.

Processing Instructions:

XML documents can contain processing instructions, which provide instructions


to applications processing the document.

Entities:

XML supports entities for representing special characters, such as < or >. For
example:

&lt;book&gt;

&lt;title&gt;Harry Potter&lt;/title&gt;

&lt;author&gt;J.K. Rowling&lt;/author&gt;

&lt;/book&gt;

Namespace:

XML namespaces are used to avoid element name conflicts. They allow elements
and attributes with the same name to be distinguished. Namespaces are
declared using the xmlns attribute.

XML documents are widely used for various purposes, including configuration
files, data interchange between systems, and representing structured data in
web services. They provide a flexible and standardized way to represent
hierarchical data structures.

What is XSLT
Before XSLT, first we should learn about XSL. XSL stands for EXtensible
Stylesheet Language. It is a styling language for XML just like CSS is a
styling language for HTML.

XSLT stands for XSL Transformation. It is used to transform XML


documents into other formats (like transforming XML into HTML).
What is XSL
In HTML documents, tags are predefined but in XML documents, tags are
not predefined. World Wide Web Consortium (W3C) developed XSL to
understand and style an XML document, which can act as XML based
Stylesheet Language.

An XSL document specifies how a browser should render an XML


document.

Main parts of XSL Document


o XSLT: It is a language for transforming XML documents into various other
types of documents.
o XPath: It is a language for navigating in XML documents.
o XQuery: It is a language for querying XML documents.
o XSL-FO: It is a language for formatting XML documents.

How XSLT Works


The XSLT stylesheet is written in XML format. It is used to define the
transformation rules to be applied on the target XML document. The XSLT
processor takes the XSLT stylesheet and applies the transformation rules
on the target XML document and then it generates a formatted document
in the form of XML, HTML, or text format. At the end it is used by XSLT
formatter to generate the actual output and displayed on the end-user.

Image representation:
Advantage of XSLT
A list of advantages of using XSLT:

o XSLT provides an easy way to merge XML data into presentation because
it applies user defined transformations to an XML document and the
output can be HTML, XML, or any other structured document.
o XSLT provides Xpath to locate elements/attribute within an XML
document. So it is more convenient way to traverse an XML document
rather than a traditional way, by using scripting language.
o XSLT is template based. So it is more resilient to changes in documents
than low level DOM and SAX.
o By using XML and XSLT, the application UI script will look clean and will be
easier to maintain.
o XSLT templates are based on XPath pattern which is very powerful in
terms of performance to process the XML document.
o XSLT can be used as a validation language as it uses tree-pattern-
matching approach.
o You can change the output simply modifying the transformations in XSL
files.
XSLT Syntax
Let's take an example to take a sample XML file and transform it into a
well formatted HTML document.

Employee.xml

<?xml version = "1.0"?>


<class>
<employee id = "001">
<firstname>Aryan</firstname>
<lastname>Gupta</lastname>
<nickname>Raju</nickname>
<salary>30000</salary>
</employee>
<employee id = "024">
<firstname>Sara</firstname>
<lastname>Khan</lastname>
<nickname>Zoya</nickname>
<salary>25000</salary>
</employee>
<employee id = "056">
<firstname>Peter</firstname>
<lastname>Symon</lastname>
<nickname>John</nickname>
<salary>10000</salary>
</employee>
</class>

Define an XSLT stylesheet document for the above XML document. You should
follow the criteria give below:

o Page should have a title employee.


o Page should have a table of employee's details.
o Columns should have following headers: id, First Name, Last Name,
Nick Name, Salary
o Table must contain details of the employees accordingly.

Step1: Create XSLT document


Create the XSLT document which satisfies the above requirements. Name
it as employee.xsl and save it in the same location of employee.xml.

Employee.xsl

<?xml version = "1.0" encoding = "UTF-8"?>


<!-- xsl stylesheet declaration with xsl namespace:
Namespace tells the xlst processor about which
element is to be processed and which is used for output purpose only
-->
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<!-- xsl template declaration:
template tells the xlst processor about the section of xml
document which is to be formatted. It takes an XPath expression.
In our case, it is matching document root element and will
tell processor to process the entire document with this template.
-->
<xsl:template match = "/">
<!-- HTML tags
Used for formatting purpose. Processor will skip them and browser
will simply render them.
-->
<html>
<body>
<h2>Employee</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Salary</th>
</tr>
<!-- for-each processing instruction
Looks for each element matching the XPath expression
-->
<xsl:for-each select="class/employee">
<tr>
<td>
<!-- value-of processing instruction
process the value of the element matching the XPath expressi
on
-->
<xsl:value-of select = "@id"/>
</td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "salary"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Step2: List the XSLT document to the XML document

Update employee.xml document with the following xml-stylesheet tag. Set


href value to employee.xsl

<?xml version = "1.0"?>


<?xml-stylesheet type = "text/xsl" href = "employee.xsl"?>
<class>
...
</class>

Updated "employee.xml"

<?xml version = "1.0"?>


<?xml-stylesheet type = "text/xsl" href = "employee.xsl"?>
<class>
<employee id = "001">
<firstname>Aryan</firstname>
<lastname>Gupta</lastname>
<nickname>Raju</nickname>
<salary>30000</salary>
</employee>
<employee id = "024">
<firstname>Sara</firstname>
<lastname>Khan</lastname>
<nickname>Zoya</nickname>
<salary>25000</salary>
</employee>
<employee id = "056">
<firstname>Peter</firstname>
<lastname>Symon</lastname>
<nickname>John</nickname>
<salary>10000</salary>
</employee>
</class>

Step3: View the XML document in Internet Explorer

The output will look like this:

Output:
Web services

The Internet is the worldwide connectivity of hundreds of thousands of computers of various

types that belong to multiple networks. On the World Wide Web, a web service is a

standardized method for propagating messages between client and server applications. A web

service is a software module that is intended to carry out a specific set of functions. Web

services in cloud computing can be found and invoked over the network.

The web service would be able to deliver functionality to the client that invoked the web

service.

A web service is a set of open protocols and standards that allow data to be exchanged

between different applications or systems. Web services can be used by software programs

written in a variety of programming languages and running on a variety of platforms to

exchange data via computer networks such as the Internet in a similar way to inter-process

communication on a single computer.

Any software, application, or cloud technology that uses standardized web protocols (HTTP

or HTTPS) to connect, interoperate, and exchange data messages – commonly XML

(Extensible Markup Language) – across the internet is considered a web service.

Web services have the advantage of allowing programs developed in different languages to

connect with one another by exchanging data over a web service between clients and servers.

A client invokes a web service by submitting an XML request, which the service responds

with an XML response.

Functions of Web Services

• It’s possible to access it via the internet or intranet networks.

• XML messaging protocol that is standardized.

• Operating system or programming language independent.

• Using the XML standard, it is self-describing.


• A simple location approach can be used to locate it.

Components of Web Service

XML and HTTP is the most fundamental web services platform. The following components

are used by all typical web services:

SOAP (Simple Object Access Protocol)

SOAP stands for “Simple Object Access Protocol.” It is a transport-independent messaging

protocol. SOAP is built on sending XML data in the form of SOAP Messages. A document

known as an XML document is attached to each message. Only the structure of the XML

document, not the content, follows a pattern. The best thing about Web services and SOAP is

that everything is sent through HTTP, the standard web protocol.

A root element known as the element is required in every SOAP document. In an XML

document, the root element is the first element. The “envelope” is separated into two halves.

The header comes first, followed by the body. The routing data, or information that directs

the XML document to which client it should be sent to, is contained in the header. The real

message will be in the body.

UDDI (Universal Description, Discovery, and Integration)

UDDI is a standard for specifying, publishing and discovering a service provider’s online

services. It provides a specification that aids in the hosting of data via web services. UDDI

provides a repository where WSDL files can be hosted so that a client application can

discover a WSDL file to learn about the various actions that a web service offers. As a result,

the client application will have full access to the UDDI, which serves as a database for all

WSDL files.

The UDDI registry will hold the required information for the online service, just like a

telephone directory has the name, address, and phone number of a certain individual. So that

a client application may figure out where it is.

If a web service can’t be found, it can’t be used. The client invoking the web service should
be aware of the location of the web service. Second, the client application must understand

what the web service does in order to invoke the correct web service. The WSDL, or Web

services description language, is used to accomplish this. The WSDL file is another XMLbased file that
explains what the web service does to the client application. The client

application will be able to understand where the web service is located and how to use it by

using the WSDL document.

How Does Web Service Work?

The diagram depicts a very simplified version of how a web service would function. The

client would use requests to send a sequence of web service calls to a server that would host

the actual web service.

Remote procedure calls are what are used to make these requests. Calls to methods hosted by

the relevant web service are known as Remote Procedure Calls (RPC). Example: Flipkart

offers a web service that displays prices for items offered on Flipkart.com. The front end or

presentation layer can be written in .Net or Java, but the web service can be communicated

using either programming language.

The data that is exchanged between the client and the server, which is XML, is the most

important part of a web service design. XML (Extensible markup language) is a simple

intermediate language that is understood by various programming languages. It is a

counterpart to HTML. As a result, when programs communicate with one another, they do so

using XML. This creates a common platform for applications written in different

programming languages to communicate with one another.

For transmitting XML data between applications, web services employ SOAP (Simple Object

Access Protocol). The data is sent using standard HTTP. A SOAP message is data that is sent

from the web service to the application. An XML document is all that is contained in a SOAP

message. The client application that calls the web service can be created in any programming

language because the content is written in XML.

Features/Characteristics Of Web Service

Web services have the following features:


(a) XML Based: The information representation and record transportation layers of a web

service employ XML. There is no need for networking, operating system, or platform binding

when using XML. At the middle level, web offering-based applications are highly

interoperable.

(b) Loosely Coupled: A customer of an internet service provider isn’t necessarily directly

linked to that service provider. The user interface for a web service provider can change over

time without impacting the user’s ability to interact with the service provider. A strongly

coupled system means that the patron’s and server’s decisions are inextricably linked,

indicating that if one interface changes, the other should be updated as well.

A loosely connected architecture makes software systems more manageable and allows for

easier integration between different structures.

(c) Capability to be Synchronous or Asynchronous: Synchronicity refers to the client’s

connection to the function’s execution. The client is blocked and the client has to wait for the

service to complete its operation, before continuing in synchronous invocations.

Asynchronous operations allow a client to invoke a task and then continue with other tasks.

Asynchronous clients get their results later, but synchronous clients get their effect

immediately when the service is completed. The ability to enable loosely linked systems

requires asynchronous capabilities.

(d) Coarse-Grained: Object-oriented systems, such as Java, make their services available

through individual methods. At the corporate level, a character technique is far too fine an

operation to be useful. Building a Java application from the ground, necessitates the

development of several fine-grained strategies, which are then combined into a rough-grained

provider that is consumed by either a buyer or a service.

Corporations should be coarse-grained, as should the interfaces they expose. Web services

generation is an easy approach to define coarse-grained services that have access to enough

commercial enterprise logic.

(e) Supports Remote Procedural Call: Consumers can use an XML-based protocol to call
procedures, functions, and methods on remote objects utilizing web services. A web service

must support the input and output framework exposed by remote systems.

Enterprise-wide component development Over the last few years, JavaBeans (EJBs) and.NET

Components have become more prevalent in architectural and enterprise deployments. A

number of RPC techniques are used to allocate and access both technologies.

A web function can support RPC by offering its own services, similar to those of a traditional

role, or by translating incoming invocations into an EJB or.NET component invocation.

(f) Supports Document Exchanges: One of XML’s most appealing features is its simple

approach to communicating with data and complex entities. These records can be as simple

as talking to a current address or as complex as talking to an entire book or a Request for

Quotation. Web administrations facilitate the simple exchange of archives, which aids

incorporate reconciliation.

The web benefit design can be seen in two ways: (i) The first step is to examine each web

benefit on-screen character in detail. (ii) The second is to take a look at the rapidly growing

web benefit convention stack.

Advantages Of Web Service

Using web services has the following advantages:

(a) Business Functions can be exposed over the Internet: A web service is a controlled

code component that delivers functionality to client applications or end-users. This capability

can be accessed over the HTTP protocol, which means it can be accessed from anywhere on

the internet. Because all apps are now accessible via the internet, Web services have become

increasingly valuable. Because all apps are now accessible via the internet, Web services

have become increasingly valuable. That is to say, the web service can be located anywhere

on the internet and provide the required functionality.

(b) Interoperability: Web administrations allow diverse apps to communicate with one

another and exchange information and services. Different apps can also make use of web

services. A .NET application, for example, can communicate with Java web administrations
and vice versa. To make the application stage and innovation self-contained, web

administrations are used.

(c) Communication with Low Cost: Because web services employ the SOAP over HTTP

protocol, you can use your existing low-cost internet connection to implement them. Web

services can be developed using additional dependable transport protocols, such as FTP, in

addition to SOAP over HTTP.

(d) A Standard Protocol that Everyone Understands: Web services communicate via a

defined industry protocol. In the web services protocol stack, all four layers (Service

Transport, XML Messaging, Service Description, and Service Discovery) use well-defined

protocols.

(e) Reusability: A single web service can be used simultaneously by several client

applications.

You might also like