Data Binding and XML in ASP.NET part two

XML does not deal with the presentation of data contained within an XML document. It concentrates only on the structure and the data contained within the structure.

This separation of the data and its presentation enables you to display the same data in various formats. However, because an XML document does not contain any formatting instructions for displaying data, you need some special tool that can convert an XML document into a user-viewable format.

The XML Document Object Model (XML DOM) is an in-memory representation of an XML document. It represents data in the form of hierarchically organized object nodes, and enables you to programmatically access and manipulate the elements and attributes present in an XML document. W3C has provided some common DOM interfaces for accessing XML documents through a program.

These standard interfaces have been implemented in different ways. Microsoft's implementation of XML DOM has the XMLDocument class, which is at the top of the document object hierarchy. It represents the complete XML document.

Another example is the XMLTransform class, which has a reference to the XSL/T file that specifies how the XML data is to be transformed. You can access XML DOM classes and objects from any scripting language as well as from programming languages such as VB.NET.

Support for XML in ASP.NET

The growing popularity of XML as a common data interchange format between Web applications has resulted in an increase in the number of software platforms that support XML, and ASP.NET is no exception. ASP.NET enables you to work with XML by supporting a number of XML-related classes. Some of the features provided in ASP.NET for working with XML are as follows:
  1. System.Xml namespace
  2. XML server-side control
  3. Data conversion from a relational to XML format
  4. Data binding with XML documents
  5. System.Xml namespace
The System.Xml namespace is a collection of classes that are used to process an XML document. This namespace supports XML-related specifications, such as DTDs, XML schemas, XML namespaces, XML DOM, and XSL/T. Some of the classes present in the System.Xml namespace are as follows:

XmlDocument: Represents a complete XML document.

XML Web server control

The XML Web server control enables you to insert an XML document as a control within a Web Form. The control has the following properties:

Converting Relational Data to XML Format

ASP.NET enables you to easily convert the data from a database into an XML document. ASP.NET provides the XMLDataDocument class, which enables you to load relational data as well as data from an XML document into a data set. The data loaded in XMLDataDocument can then be manipulated using the W3C Document Object Model.

You can also set the ContentType property to HTML to indicate that the page contains HTML elements. This statement is given to ensure that the contents of the resulting output are processed properly. The next step is to import all the necessary namespaces. In addition to including the System.Data and System.Data.SQL namespaces, you are also required to include the System.Xml namespace, because it contains all classes required to process an XML
document.

After importing the namespaces, you need to establish a connection with the SQL server and fetch the required data.

Binding server-side controls with data in XML files

ASP.NET enables you to associate server controls with a variety of sources, including XML files. You can think of an XML file as a special data table that contains data embedded within the tags that describe the data.

You cannot bind an XML document directly to a server-side control because it contains data in a plain-text format. You must first load XML data as a data table into a data set. After loading the data into a data set, you can bind it to a server-side control. In this section, you will create a file "Products.xml" and bind a DropDownList control to the "ProductID" tag in the file. When a user selects a product ID from the DropDownList control, the details about the product will be displayed in a DataGrid control.

related post

CREATING ASSEMBLIES WITH ASP.NET

BUILDING HANDLERS IN ASP.NET

INTERFACES AND CLASSES CREATION IN ASP.NET

CACHING IN ASP.NET

CACHING IN ASP.NET PART TWO

WIRE LESS APPLICATION WITH ASP.NET

SECURITY IN ASP.NET PART ONE

SECURITY IN ASP.NET PART TWO

LOCALIZING ASP.NET APPLICATIONS

DEPLOYING ASP.NET APPLICATIONS

ASP.NET CONFIGURATION SYSTEM

WEB SERVICES IN ASP.NET

WEB SERVICES PART TWO

WEB SERVICE INFRASTRUCTURE

WEB SERVICE INFRASTRUCTURE PART TWO

EXCHANGING MESSAGES IN ASP.NET

MICROSOFT HAIL STORM

SOAP AND DOT NET PART ONE

SOAP AND DOT NET PART TWO


No comments:

Post a Comment