Showing posts with label Data Binding and XML. Show all posts
Showing posts with label Data Binding and XML. Show all posts

XML INTRODUCTION DAY 5

1. XML shall be straightforwardly usable over the Internet.

This does not mean that XML should only be used over the Internet, but rather that it should be lightweight and easily usable over the Internet.

2. XML shall support a wide variety of applications.

The idea here is that XML should not be application specific. It can be used over the Internet or in a traditional client/server application. There is no specific technology behind XML, so any technology should be able to use it.

3. It shall be easy to write programs that process XML documents.

Unable to gain wide acceptance for various reasons, many technologies come and go. A major Barrier to wide acceptance is a high level of difficulty or complexity.

The designers of XML wanted to ensure that it would gain rapid acceptance by making it easy for programmers to write XML parsers.

4. XML documents should be human-legible and reasonably clear.

Because XML is text-based and follows a strict but simple formatting methodology, it is extremely easy for a human to get a true sense of what a document means. XML is designed to describe the structure of its contents.

5. XML documents shall be easy to create.

XML documents can be created in a simple text-editor. Now that’s easy!There are other XML guidelines, but since this only is an introduction to XML, these will do for now. The important thing to remember is that XML is simply a file format that can be used for two or more entities to exchange information.

XML documents are hierarchical: they have a single (root) element, which may contain other elements, which may in turn contain other elements, and so on. Documents typically look like a tree structure with branches growing out from the center and finally terminating at some point with content. Elements are often described as having parent and child relationships, in which the parent contains the child element.


XML documents must be properly structured and follow strict syntax rules in order to work correctly. If a document is lacking in either if these areas, the document can’t be parsed.

There are two types of structures in every XML document: logical and physical. The logical structure is the framework for the document and the physical structure is the actual data.

An XML document may consist of three logical parts: a prolog (optional), a document element, and an epilog (optional). The prolog is used to instruct the parser how to interpret the document element. The purpose of the epilog is to provide information pertaining to the preceding data.

60.81
RELATED POST

DATA BASE CREATION FOR DOT NET

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


Data Binding and XML in ASP.NET

The World Wide Web and its rapid growth in the 1990s revolutionized the methods of accessing information and conducting commerce. Numerous companies use the Web as a powerful tool to advertise and sell their products. This has led to an increase in the number of Web applications and their requirements in terms of payment handling, data access, and security. As a result, various new technologies have evolved.

One of the most important requirements of Web applications, especially B2B ecommerce applications, is the ability to interchange data in a standard format that can be understood by any hardware and software platform. Enterprises having similar business interests may need to share data, which may be stored on disparate platforms. This need for a common interface for exchanging data resulted in the evolution of Extensible Markup Language (XML), which is the latest and the most hyped Web technology.

XML is the World Wide Web Consortium's (W3C) specification for interchanging structured data in Web applications. An XML document enables you to store data in the same way a database enables you to store data. However, unlike databases, an XML document stores data in the form of plain text, which can be understood by any type of device, whether it is a mainframe computer, a palmtop, or a cell phone. Thus, XML serves as a standard interface required for interchanging data between various Web applications.

W3C is a consortium that ensures the growth of the Web by developing common protocols for the Web. It also ensures that various Web technologies are interoperable. W3C has more than 500 organizations as its members.

XML is a markup language that enables you to enclose data within tags.

So how is it different from HTML?

The difference lies in the fact that HTML has a set of predefined elements that concentrate on the appearance of the contents within the document. For example, when you enclose the data within the and tags, the browser interprets these tags and displays the content enclosed within the tags in italics. The browser is not concerned about the contents within the tags.

Conversely, XML concentrates on the content in the document and is not concerned with how the contents should appear. For example, if you are creating a document that stores the data about the products offered by your company, you can create a tag called and enclose the description of a product within this tag.

Thus, tags in XML serve the purpose of structuring the content within the XML document. No presentation or appearance is associated with any of the XML tags. XML does not provide any predefined set of tags. Rather, it enables you to create your own tags. In that sense, XML can be called a meta-markup language, which enables you to create your own markup or vocabulary. In fact, many existing markup languages have been derived from XML.

Some examples of markup languages that are based on XML are Wireless Markup Language (WML), which is used to create Web applications that can be accessed using a cell phone, and MathML, which is used to represent mathematical equations.

XML does not exist all by itself. Numerous additional XML-related specifications provide guidelines for working with XML documents. Before discussing the implementation of XML in ASP.NET, it is important to understand these XML-related specifications. Therefore, this section looks at some of the important XML-related W3C specifications.

Document Type Definition

A Document Type Definition (DTD) enables you to specify the structure of the content in an XML document. Creating a DTD is similar to using a CREATE TABLE statement in SQL, in which you specify the columns to be included in the table and whether they can hold null values. In a DTD, you can specify the elements that can be used in an XML document and specify whether it is mandatory to provide values for the elements.

When you include a DTD in an XML document, software checks the structure of the XML document against the DTD. This process of checking the structure of the XML document is called validating. The software that performs the task of validating is called a parser.

The following are the two types of parsers:

Nonvalidating parser: Checks whether an XML document is well formed. An example of a nonvalidating parser is the expat parser.

Validating parser: Checks whether an XML document is well formed and whether it conforms to the DTD that it uses. The MSXML parser provided with Microsoft Internet Explorer 5.0 is an example of a validating parser.

An XML document that conforms to the DTD is called a valid document.

XML namespaces

XML enables you to create your own elements. It also enables you to use elements that are defined for and used by various software modules. This may lead to certain problems. For example, in case of a purchase order, you may have an element called QTY that stores the quantity of a purchase.

In some other case, the same element may be used to store the quantity on hand for a particular item. In such a case, there may be a collision of elements having the same names. To prevent this from happening, W3C has recommended the use of XML namespaces.

XML namespaces use Uniform Resource Identifiers (URIs) to differentiate tags used in different vocabularies. With this approach, each element can be uniquely identified using the namespace. A namespace can be declared using the xmlns keyword. For example,

a namespace for a purchase order could be defined in the following way:

xmlns:PurchaseOrder="http://www.po.com/po"

XML schemas

An XML schema provides a way of defining a structure of an XML document. It enables you to describe the elements and attributes that can be present in an XML document. An XML schema is similar to a DTD. However, it can be considered a superset of a DTD in terms of the functionality that it provides. An advantage of using an XML schema is that it enables you to specify the data types for elements.

A DTD, on the other hand, enables you to specify whether the element can contain character data or other elements, or whether it is an empty element. It does not enable you to specify whether a particular element should contain integer, float, or string values. Another difference between an XML schema and a DTD is that an XML schema follows XML syntax. In other words, it is an application of XML, whereas a DTD has its own syntax.

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


XML in ADO.NET

XML is the behind-the-scenes foundation of ADO.NET. Data is described in the XML format, and XML representations of DataSet objects, DataTable objects, and schemas can be written from in-memory representations of data and persisted as XML text files or streams. The XmlDataDocument class allows you to work directly with in-memory representations of XML and synchronize them with a DataSet.

Retrieving XML from a SQL Server 2000 Database

Microsoft SQL Server 2000 contains built-in support for XML-based data access. Data can be retrieved from the database and read into memory in the XML format. The ADO.NET SQL Data Provider provides built-in support for retrieving XML from the database.

Retrieving an XmlReader with a SqlCommand

The SqlCommand class provides a method for retrieving data as XML. The ExecuteXmlReader returns an XmlReader object that exposes the data returned by the SqlCommand as a set of XML rows. The SQL SELECT query executed by the ExecuteXmlReader method must contain a FOR XML clause. This method is only available with the SqlCommand class and can only be used when connecting to Microsoft SQL Server 2000 or later.

The XmlReader class is analogous to the DataReader class. It provides read-only, forward-only access to the XML returned by the query. Also like the DataReader, the XmlReader requires the exclusive use of a connection.

The XmlReader exposes a Read method, similar to the Read method of a DataReader, which allows you to iterate through the nodes that are returned. Like a DataReader, the Read method advances the XmlReader to the next node of the XML stream and returns false when the last node is reached. Also like the DataReader, you must call the Read method before the first node is accessible.

Using XML with DataSets

DataSets provide methods for interacting with data stored as XML. You can load data stored as an XML file or stream into a DataSet or write the data represented in a DataSet to an XML file or stream. You can create typed DataSet objects of a known structure by reading an XML schema into the DataSet, and you can create a template for other typed DataSets by writing the structure of the DataSet to an XML schema.

Reading XML into a DataSet

You can access XML data stores by using the DataSet.ReadXml method. This method allows you to specify an existing XML file or stream, or an existing XmlReader or TextReader object, and read the schema and data represented therein into a DataSet.
  1. To read XML into a DataSet
  2. Call the DataSet.ReadXml method.
  3. To read an XML schema into a DataSet
  4. Call the DataSet.ReadXmlSchema method.
  5. Writing XML from a DataSet
DataSet objects can write the data they contain and the schema that describes the data as XML files. The DataSet object provides the WriteXml method to facilitate exporting data to an XML format. The WriteXml method allows you to specify a file, a stream, or an XmlWriter or TextWriter object to receive the XML output from the DataSet. The following example demonstrates how to write the contents of a DataSet to an XML file called myXml.xml. If the specified file is not present, it will be created automatically.

Executing XSLT Transformations

XSLT is designed to facilitate transforming XML data into different formats. For example, an XML document might be converted to HTML for display on a Web page or might be converted to a different XML format for a specialized application.

The .NET Framework provides the XslTransform class to execute XSLT transformations. To execute a transformation, the XslTransform class first needs to load a style sheet. This is a file that contains the formatting instructions for the XML data. You use the XslTransform.Load method to load the style sheet. The style sheet can be specified as either a URL that points to an XSL file that contains the style definitions or as any of a number of classes that contain an in-memory representation of the style sheet.

RELATED POST

DAY 11 OOPS INTRODUCTION

DAY 12 POLYMORPHISM

DAY 13 INHERITANCE AND POLYMORPHISM

DAY 14 EBUGGING TOOLS IN DOT NET

DAY 15 DEBUG AND TRACE IN CLASSES

DAY 16 UNIT TEST PLAN

DAY 17 EXCEPTIONS IN VISUAL STUDIO

DAY 19 ADO.NET INTRODUCTION

DAY 20 DATA ACCESSING IN DOT NET

DAY 21 DATA BASE OBJECTS