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

XML Basics

The document discusses XML basics, differences between XML and HTML, features of XML, an XML example, .NET support for XML, and an introduction to web services. Key points include: XML was designed to store and transport data, unlike HTML which was designed to display data; XML is extensible and defines its own tags; .NET provides strong support for XML through classes, designers, controls, and DOM; web services allow different applications to communicate and exchange data over a network using standard protocols like HTTP and SOAP.

Uploaded by

Arjun Domle
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

XML Basics

The document discusses XML basics, differences between XML and HTML, features of XML, an XML example, .NET support for XML, and an introduction to web services. Key points include: XML was designed to store and transport data, unlike HTML which was designed to display data; XML is extensible and defines its own tags; .NET provides strong support for XML through classes, designers, controls, and DOM; web services allow different applications to communicate and exchange data over a network using standard protocols like HTTP and SOAP.

Uploaded by

Arjun Domle
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Unit-2 ASP.

NET-2
XML Basics:
• XML stands for eXtensible Markup Language.
• XML is a markup language much like HTML.
• XML was designed to store and transport data.
• XML was designed to be self-descriptive.
• XML is a W3C Recommendation.
• XML is not a replacement for HTML.
• XML is designed to carry data, not to display data.
• XML tags are not predefined. You must define your own tags.
• XML is platform independent and language independent.
• XML is a software- and hardware-independent tool for storing and transporting data.
1) Difference Between XML and HTML:
HTML is a popular language and contains more than 100 tags to display data in webpages. But
it is hard to remember and use all the tags in HTML. And also, HTML’s presentation changes
according to browsers. One more problem is that in HTML document we use more tags than
actual original content. These all problems are solved using XML by combining XML and
HTML i.e. by using X-HTML. 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.
One more important difference is XML and HTML were designed with different goals: XML
was designed to carry data - with focus on what data is and HTML was designed to display
data - with focus on how data looks.

2) Features of xml :
• XML is powerful and excellent option to handle complex structure of data.
• By using xml we can give description of data in text format.
• 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 handles the data in tree structure.
• For storing data for a long time and using that data xml is better choice than any other.
3) XML Example :
<?xml version=“1.0” encoding=“UTF-8” standalone=“yes”?>
<person>
<name>Ram</name>
<age>24</age>
</person>
4) .NET Support for XML :
Although many programming languages and environments have provided XML support as an
add-on, .NET’s support is integrated into the framework more tightly than most. The .NET
development team decided to use XML extensively within the framework in order to meet its
design goals. Accordingly, they built in XML support from the beginning. The .NET
Framework has extensive support for working with XML documents. In the .NET framework,
the support for XML documents includes:
XML namespace
XML designer
XML Web Server control
XML DOM support

1. XML Namespace
The System.Xml namespace provides a rich set of classes for processing XML data. The
commonly used classes for working with XML data are:
• XmlTextReader: Provides forward only access to a stream of XML data and checks
whether or not an XML document is well formed. This class neither creates as in-memory
structure nor validates the XML document against the DTD. You can declare an object of
the XmlTextReader class by including the System.Xml namespace in the application. The
syntax to declare an object of this class is as follows:
XmlTextReader reader = new XmlTextReader("XML1.xml");
• XmlTextWriter: Provides forward only way of generating streams or files containing XML
data. If you want to declare an object of the XmlTextWriter class, you must include the
System.Xml. The syntax to declare an object of this class is as follows:
XmlTextWriter writer = new XmlTextWriter(Response.Output);
• XmlDataDocument: Provides support for XML and relational data in XML DOM. You
can use this class with a dataset to provide relational and non-relational views of the same
set of data. This class is primarily used when you want to access the functions of
ADO.NET. The syntax to declare an object of this class is as follows:
DataSet ds=new DataSet();
XmlDataDocument doc=new XmlDocument(ds);

2. XML Designer
Visual Studio .NET provides the XML designer that you can use to create and edit XML
documents.
3. XML Web Server Control
An XML Web Server control is used to display the contents of an XML document without
formatting or using XSL Transformations. You can optionally specify a XSLT style sheet that
formats the XML document before it is displayed in an XML server control. The XML Web
Server control belongs to the System.Web.UI. Web Controls namespace. You can add an XML
Web Server control to a Web form by dragging the control from the Web forms tab of the
toolbox.
4. XML Document Object Model Support
When you want to access and display XML data in Web Applications, you use the XML Web
server control and set its properties at design time. In certain situation, you may need to display
the XML data based on specific conditions. In such cases, you will have to access the XML
data programmatically.
An XML document consists of elements and attributes. For this reason, you can access XML
data programmatically. Note that XML DOM allows you to access and manipulate the elements
and attributes present in an XML document programmatically.

XML Validation:

Validation is a process by which an XML document is validated. An XML document is said to


be valid if its contents match with the elements, attributes and associated document type
declaration (DTD), and if the document complies with the constraints expressed in it.
Validation is dealt in two ways by the XML parser. They are −
• Well-formed XML document
• Valid XML document

➢ Well-formed XML Document:


1. An XML document is said to be well-formed if it adheres to the following rules −
2. Non DTD XML files must use the predefined character entities for amp(&), apos(single
quote), gt(>), lt(<), quot(double quote).
3. It must follow the ordering of the tag. i.e., the inner tag must be closed before closing the
outer tag.
4. Each of its opening tags must have a closing tag or it must be a self-ending
tag.(<title>....</title> or <title/>).
5. It must have only one attribute in a start tag, which needs to be quoted.
6. amp(&), apos(single quote), gt(>), lt(<), quote(double quote) entities other than these must
be declared.

Example:
Following is an example of a well-formed XML document −
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
<!DOCTYPE address
[
<!ELEMENT address (name,company,phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
]>
<address>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</address>

The above example is said to be well-formed as −


• It defines the type of document. Here, the document type is element type.
• It includes a root element named as address.
• Each of the child elements among name, company and phone is enclosed in its self
explanatory tag.
• Order of the tags is maintained.

A well-formed XML document can be validated against DTD or Schema.


1. DTD (Document Type Definition):
DTD technique is used to define the structure of xml document. DTD is text based document
with .dtd extension. DTD contain element declaration,attribute declaration,entity declaration.
A DTD defines the legal elements of an XML document
In simple words we can say that a DTD defines the document structure with a list of legal
elements and attributes.
Example :
<!ELEMENT address(name,company,phone)>
<!ELEMENT name(#PCDATA)>
<!ELEMENT company(#PCDATA)>
<!ATTLIST name id CDATA #REQUIRED>
<!ENTITY phone (#PCDATA)>
• Types of DTD :
Internal DTD : A DTD is referred to as an internal DTD if elements are declared within the
xml files.

External DTD : In external DTD elements are declared outside the xml file.

2. XSD :
XML schema is commonly known as XML Schema Definition (XSD).
It is used to describe and validate the structure and the content of xml data.
Xml schema defines the elements, attributes and data types.
XML schema is a XML based alternative to DTD. Actually DTD and XML schema both are
used to form a well-formed XML document.
• Types of XSD:

Example :

➢ Valid XML Document:


If an XML document is well-formed and has an associated Document Type
Definition/Declaration (DTD), then it is said to be a valid XML document.

Introduction to web services:


Web services are components on a Web server that a client application can call by making
HTTP requests across the Web. ASP.NET enables you to create custom Web services or to use
built-in application services, and to call these services from any client application. Basically,
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. Web Service is known as the software program. These services use the XML to
exchange the information with the other software with the help of the common internet
Protocols. In the simple term, we use the Web Service to interact with the objects over the
internet.
In simple sense, Web Services are means for interacting with objects over the Internet. The
Web service consumers are able to invoke method calls on remote objects by using SOAP and
HTTP over the Web.
Webservice is language independent and Web Services communicate by using standard web
protocols and data formats.
A web service is an XML-based information exchange system that creates direct interaction
between the two applications over the internet or network in order to exchange data or
information.
It enables us to communicate and exchange data or information between the two different
applications created in the same or different languages over the internet or network.
For example, if we use multiple software systems and we need to transfer data from one
application to another application then a web service is the best source to accomplish this task.
The software system that sends requests for data is called a service requester whereas the
software system that would process the request and provide the data is called a service provider.
A web service works between all types of applications software and it does not matter if both
the service requester software and service provider software are written in different
programming languages because web services use XML files for data exchange and most
software applications, however, interpret XML tags.
Technology Used in Web Service:
XML: Web Service specifies only the data. So, the application which understands the XML
regarding the programming language or the platform can format the XML in different ways.
SOAP: SOAP stands for Simple Object Access Protocol. It is a communication protocol that
is responsible for allowing communication and messages transfer between the two different
applications of the same or different platform and the same or different programming
languages. The communication between the Services and the application is set up by the SOAP.
The SOAP protocol is language independent and platform independent that sends and receives
messages between the different applications without facing the interoperability issues.
WSDL: WSDL stands for Web Service Description Language. It is a standard that describes
the availability of service. It enables a web service to tell to the clients that what messages it
accepts and which results it will return. WSDL gives us a uniform method that is helpful to
specify the Web Services to the other programs. The WSDL is written in XML and it is used
in the combination with the SOAP and XML schema to provide web services over the internet.
UDDI: UDDI stands for Universal Description Discovery and Integration. With the help of
UDDI, we can search the Web Service registries. At the time of the deployment of these
technologies, this allows the developers to do the packaging of the applications in the form of
the Service and publishing of the Service on the network. The UDDI is an XML-based standard
that lists what services are available. The UDDI uses WSDL to describe interfaces to web
services. It can communicate via SOAP, CORBA, and Java RMI Protocol.
Advantages of Web Services:
• Web Services always use the open, text-based standard. Web service uses all those
components even they are written in various languages for different platforms.
• Web Service promotes the modular approach of the programming so that the multiple
organizations can communicate with the same web service.
• Web Services are easy to implement but expensive because they use the existing
infrastructure, and we can repackage most of the applications as the Web Service.
• Web Service reduces the cost of enterprise application integration and B2B
communications.
• Web Services are the interoperable Organization that contains the 100 vendors and promote
them interoperability.

Limitations of Web Services:


• One of the limitations of the Web Services is that the SOAP, WSDL, UDDI requires the
development.
• The limitation of web service is also royalty fees.
• If we want to use web services for the high-performance situation, in that case, web service
will be slow.
• The use of web service increases the traffic on the network.
• The security level for Web Services is low.
• We use the standard procedure to describe the quality of particular web services.
• The standard for the Web Service is in the draft form.
• To retain the intellectual property of the specific standard by the vendor is also the
limitation of the web service.

Example of the Web Service :


Web Service can do almost any kind of task.
• Web Portal: Web portal is used to fetch the headline news from the linked web service.
• Weather Reporting: For the reporting of weather, we will use Weather Reporting Web
Service for displaying the information about the weather on our website.
• Stock Quote: The latest information about the share market with the Stock Quote can
display on our website.
• News headline: By using the news headline Web Service, we can show the latest update
of the news on our website.
• We can make our web service and can give them back to use.
The need for Web Service:
We will think about a scenario which we want to show on our website. On our website, we
want to show the information about the region, nation and about the international as well. Here
if we are thinking of writing the code for all these functionalities, this will take lot of time and
the effort to write the code for all these functionalities. All of the above information is already
provided by some existing sites, so in that case, we want to use that current logic of other sites.
But there is a problem arises how could we use the existing logic in my application.
The solution to this problem is Web Services.
By using the Web Service, we can reuse someone else's business logic, instead of replicating
this. To use the business logic of someone else, we just have to write a few lines of the code.
This technique is similar to the libraries of API, DLLs, and plug-ins.

State Management:
State management in any application plays a vital role in preserving the states of users, web
pages, objects, or controls. As .NET developers know, HTTP is a stateless protocol, so all
online ASP.NET web applications are also stateless by default. That means the web application
cannot preserve the state of control for each page submitted to the server. In the modern era of
web applications, there is a high demand for state management. We know that web applications
work on client-server technology and follows the HTTP protocol. As HTTP protocol is a
stateless protocol, it does not store the information provided by the user. This is because the
web applications are deployed on a centralized server and the request can come from any
random client machine. If the server starts retaining each and every information provided by
the user then it will lead to the unnecessary consumption of memory and could even run out of
storage. So, Asp.net provides state management techniques to restore the data provided by the
user. State Management could also be defined as the process of the persistence of the values
between multiple request-response cycles. These state management techniques are of two
types:-
• Client-Side State Management Techniques - To maintain the state of values on the client’s
machine, we use the client-side state management techniques. Whenever we use Client-
Side State Management, the state related information will directly get stored on the client-
side. That specific information will travel back and communicate with every request
generated by the user then afterwards provides responses after server-side communication.
Client side state management techniques are :
1. Hidden field
Hidden field is a control provided by ASP.NET which is used to store small amounts of data
on the client. It stores one value for the variable and it is a preferable way when a variable's
value is changed frequently. Hidden field control is not rendered to the client (browser) and it
is invisible on the browser. A hidden field travels with every request like a standard control’s
value.
2. View state
View state is another client-side state management mechanism provided by ASP.NET to store
user's data, i.e., sometimes the user needs to preserve data temporarily after a post back, then
the view state is the preferred way for doing it. It stores data in the generated HTML using
hidden field not on the server. View State provides page level state management i.e., as long
as the user is on the current page, state is available and the user redirects to the next page and
the current page state is lost. View State can store any type of data because it is object type but
it is preferable not to store a complex type of data due to the need for serialization and
deserialization on each post back. View state is enabled by default for all server side controls
of ASP.NET with a property EnableviewState set to true.
3. Cookies
Cookie is a small text file which is created by the client's browser and also stored on the client
hard disk by the browser. It does not use server memory. Generally, a cookie is used to identify
users. A cookie is a small file that stores user information. Whenever a user makes a request
for a page the first time, the server creates a cookie and sends it to the client along with the
requested page and the client browser receives that cookie and stores it on the client machine
either permanently or temporarily (persistent or non persistence). The next time the user makes
a request for the same site, either the same or another page, the browser checks the existence
of the cookie for that site in the folder. If the cookie exists it sends a request with the same
cookie, else that request is treated as a new request.
Types of Cookies
1. Persistence Cookie: Cookies which you can set an expiry date time are called persistence
cookies. Persistence cookies are permanently stored till the time you set.
2. Non-Persistence Cookie: Non persistence cookies are not permanently stored on the user
client hard disk folder. It maintains user information as long as the user accesses the same
browser. When user closes the browser, the cookie will be discarded. Non-Persistence cookies
are useful for public computers.

4. Control State
Control State is another client side state management technique. Whenever we develop a
custom control and want to preserve some information, we can use view state but suppose view
state is disabled explicitly by the user, the control will not work as expected. For expected
results for the control we have to use Control State property. Control state is separate from
view state.

• Server-Side State Management Techniques - To maintain the state of values on the server’s
machine, we use the server-side state management techniques. Server-Side State
Management is different from Client-Side State Management but the operations and
working is somewhat the same in functionality. In Server-Side State Management all the
information is stored in the user memory. Due to this functionality, there are more secure
domains at the server side in comparison to Client-Side State Management. Server side
state management techniques are :
1. Session state:
Session management is a very strong technique to maintain state. Generally, session is used to
store user's information and/or uniquely identify a user (or say browser). The server maintains
the state of user information by using a session ID. When users make a request without a session
ID, ASP.NET creates a session ID and sends it with every request and response to the same
user.
2. Application State:
The ASP.NET application is the collection of all web pages, code and other files within a single
virtual directory on a web server. When information is stored in application state, it is available
to all the users. To provide for the use of application state, ASP.NET creates an application
state object for each application from the HTTPApplicationState class and stores this object in
server memory. This object is represented by class file global. Sax. Application State is mostly
used to store hit counters and other statistical data, global application data like tax rate, discount
rate etc. and to keep the track of users visiting the site.

Using session in asp.net:


Session management is a very strong technique to maintain state. Generally, session is used to
store user's information and/or uniquely identify a user (or say browser). ASP.NET session
state enables you to store and retrieve values for a user as the user navigates ASP.NET pages
in a Web application.
HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page
as an independent request. The server retains no knowledge of variable values that were used
during previous requests. ASP.NET session state identifies requests from the same browser
during a limited time window as a session, and provides a way to persist variable values for the
duration of that session.
By default, ASP.NET session state is enabled for all ASP.NET applications.
The server maintains the state of user information by using a session ID. When users make a
request without a session ID, ASP.NET creates a session ID and sends it with every request
and response to the same user.
Alternatives to session state include the following:
• Application state, which stores variables that can be accessed by all users of an ASP.NET
application.
• Profile properties, which persists user values in a data store without expiring them.
• ASP.NET caching, which stores values in memory that is available to all ASP.NET
applications.
• View state, which persists values in a page.
• Cookies, which is a small file that stores user information.
• The query string and fields on an HTML form that are available from an HTTP request.
Session Variables :
Session variables are stored in a SessionStateItemCollection object that is exposed through the
HttpContext.Session property. In an ASP.NET page, the current session variables are exposed
through the Session property of the Page object.
The collection of session variables is indexed by the name of the variable or by an integer
index. Session variables are created by referring to the session variable by name. You do not
have to declare a session variable or explicitly add it to the collection. The following example
shows how to create session variables in an ASP.NET page for the first and last name of a user,
and set them to values retrieved from TextBox controls.
Session("FirstName") = FirstNameTextBox.Text
Session("LastName") = LastNameTextBox.Text

Caching in asp.net:
Caching is a technique of storing frequently used data/information in memory, so that, when
the same data/information is needed next time, it could be directly retrieved from the memory
instead of being generated by the application.
Caching is extremely important for performance boosting in ASP.NET, as the pages and
controls are dynamically generated here. It is especially important for data related transactions,
as these are expensive in terms of response time.
Caching places frequently used data in quickly accessed media such as the random-access
memory of the computer. The ASP.NET runtime includes a key-value map of CLR objects
called cache. This resides with the application and is available via the HttpContext and
System.Web.UI.Page.
In some respect, caching is similar to storing the state objects. However, the storing information
in state objects is deterministic, i.e., you can count on the data being stored there, and caching
of data is nondeterministic.
ASP.NET provides the following different types of caching:
Output Caching : Output cache stores a copy of the finally rendered HTML pages or part of
pages sent to the client. When the next client requests for this page, instead of regenerating the
page, a cached copy of the page is sent, thus saving time.
Data Caching : Data caching means caching data from a data source. As long as the cache is
not expired, a request for the data will be fulfilled from the cache. When the cache is expired,
fresh data is obtained by the data source and the cache is refilled.
Object Caching : Object caching is caching the objects on a page. The cached data is stored in
server memory.
Class Caching : Web pages or web services are compiled into a page class in the assembly,
when run for the first time. Then the assembly is cached in the server. Next time when a request
is made for the page or service, the cached assembly is referred to. When the source code is
changed, the CLR recompiles the assembly.
Configuration Caching : Application wide configuration information is stored in a
configuration file. Configuration caching stores the configuration information in the server
memory.

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