-->

Sunday, November 3, 2013

Primitive Data Type in XML Schemas

Introduction

Primitive data type are the fundamental data types of XSD. These data types are the basis for defining other data types in XSD. Primitive data types dot not contain elements or attributes. They contain only values.

Some of the primitive data types supported by XSD are listed in the following table.

Primitive Data Type
Description
String
Represents a collection of characters.
Decimal
Represents decimal numbers. This can be used to accurately define a value.
Float
Represents single-precision 32-bit floating-point numbers
Boolean
Represents Boolean values. This data type can have a value of true or false
timeDruration
Represents certain duration of time.
RecurringDuration
Represents a time duration that recurs after a specific interval.

Advantages of XML Schemas Created Using XSD

An XML schema defines the list of elements and attributes that can be used in an XML document. In addition to the list of elements, an XML schema specifies the order in which these elements appear in the XML document, and their data types.
Microsoft has developed the XML Schema Definition(XSD) language to define the schema of an XML document. XML schema s  have now become a w3c recommendation for creating valid XML documents.

Advantages of XML Schema s Created Using XSD
Some of the advantages of creating an XML schema by using XSD are:

  • XSD provides control over the type of data that can be assigned to elements and attributes.
  • XSD enables you to create your own data types. This feature enhances the flexibility of defining the structure of the XML document.
  • XSD enables you to specify restriction on data. For example, you can ensure that the content of an element is a positive integer value.
  • The syntax for defining an XSD is the same as the syntax used for xml documents. Therefore, it is easier to learn the syntax of an XSD.
  • XML schema content models can be used to validate mixed content.
  • XML schema is extensible. This enables you to reuse parts of a schema in another schema and derive custom data types from existing data types.
  • XML schema is self documenting. Using the annotation element you can specify the intended purpose and attribute of a schema. This enables effective use of the schema by other.

Saturday, November 2, 2013

Creating an XML Document

Problem Statement

CyberShoppe, Inc. sells toys and books in the United States. It has three branches in different parts of the country. Currently, the three branches maintain data on their local computer systems. The IT manager at CyberShoppe has identified that a centralized data repository on the products sold through its e-commerce site is required. The data from all branches must be collated and housed in a centralized location. This data must be made available to the accounts and sales sections at the individual branches, regardless of the hardware and software platforms being used at the branches. In addition, the sales personnel require access to the data using palmtops and cellular phones.
The product details of CyberShoppe consists of the product name, a brief description, the price, and the available quantity on hand. A product ID uniquely identified each product.

Solution
To solve the preceding problem, you need to perform the following tasks:

  1. Identify the method to store data in a device-independent format.
  2. Identify the structure of the document in which data is to be stored.
  3. Create an XML document to store the data.
  4. View the XML document in a browser.

Task 1: Identifying the method to store the Data in a Device-Independent Format

In the given problem statement, device ranging from mainframe computers to mobile phones must be able to access information from the data store. For example, the employee of the sales department may need to access product costs using an IBM PC. XML enables different types of devices to access information. Therefore, XML can be used to create the data store in the given scenario.

Task 2 : Identifying the Structure of the Document in Which Data is to be stored.

In the given scenario, PRODUCTDATA has been Identified as the root element. It has one child element, PRODUCT. The PRODUCT element can occur one or more times in the XML document. It acts as the container element for the PRODUCTNAME , DESCRIPTION, PRICE, AND QUANTITY elements. PRODUCTNAME has one attribute called PRODID, which is used to uniquely identify each product. The following figure illustrate the structure of the elements used in the XML document to store the product data.

Creating an XML Document
Structure of the XML Document to Store Product Data

Task 3: Creating an XML Document to Store Data

To create an XML file that contains information about the products sold by CyberShoppe, type the following code in Notepad, and save the file as cyber_products.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- PRODUCTDATA is the root element -->
<PRODUCTDATA>
<PRODUCT PRODID="P001">
<PRODUCTNAME>Barbie Doll</PRODUCTNAME>
<DESCRIPTION>This is a toy for children in the age group of 5-10 years </DESCRIPTION>
<PRICE>12</QUANTITY>
</PRODUCT>
</PRODUCTDATA>

Task 4: Viewing the XML Document in a Browser

To View the XML document in the browser, open the cyber_products.xml file in Internet Explorer . IE provides a default tree view layout for an XML document. You can expand and collapse the tree.

The tree-view structure of the cyber_products.xml document is shown in the following figure

Creating an XML Document



Future of XML

XML has revolutionized the web and the nature of distributed computing. It is the preferred file format for web development, document interchange, and data interchange. Currently, news organizations and wireless services exchange news articles, stock information, and other similar information through proprietary formats. XML will enable wider use and exchange of such information in future. XML will also help global businesses exchange data in a customized and universally acceptable format.
The future uses of XML can be summarized as:

  • XML will be widely used in e-commerce.
  • XML will have a huge core market in the form of B2B.
  • XML will be used for mobile devices, such as mobile phones, PDAs, and palmtops due to its ability to easily convert into the appropriate format for any device.
  • XML will be used to solve communication problems in EDI and Enterprise Application Integration(EAI) as it provides interoperability between disparate  applications.
Lets us look at some real life examples of XML implementation.
identifying Real-Life implementation of XML 
The Microsoft site, http://msdn.microsoft.com/xml/, provides information about customers who have successfully implemented XML in real-life. A few of these customers are listed as follows:
  • FreeEDGAR.com, Inc. is an organization that provides updated information on finance, institutional holdings, and insider trading patterns to its customers. To provide this information, FreeEDGAR.com uses an XML based delivery service. This service is based on real-time filling from the US securities and Exchange commission. One of the project requirements was that FreeEDGAR's customers should be able to use the service on multiple platforms. The service had to be independent of any database technology. FreeEDGAR also had to ensure are able to query and access the structured information easily. The development team realized that XML was the perfect solution for its project's requirements. The team used a processing server and built its XML service on top of it. To generate Web Pages, it used MSXML DLL along with some XSL style sheets that were used to convert XML into HTML. The team used MSXML inside a Web page created using Visual InterDev and Visual Basic components. This approach reduced code maintenance and resulted in the development of more readable code.
  • Shopping.com is another example of the real life implementation of XML. Shopping.com uses context based shopping to ensure that its uses get relevant results for their searches. The organization had to ensure that the users who conduct keyword searches through AltaVista Search also receive suitable product offers from Shopping.com for example, The keyword , "CD player", on AltaVista Search will return Web search results along with relevant CD players and electronics merchandise available for purchase from shopping.com. The development team faced the challenge of ensuring quick transfer of data between two different operating systems. Since the XML syntax is simple to learn and can be used quickly , they decided to use XML for the project. The use of XML enabled them to reduce the size of the data file and the time taken to transfer the data file to a great extent.

Programmatically change CheckBoxList text color in ASP.NET

Introduction

If you want to change foreColor of the font for better visibility then you must change font color according to users. Highly rich content website change font color , font name/face and font size according to users. Get lots of visitors or viewers from your website  using website functionality (better presentation, better look and better theme) .

lets take an simple example

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckBoxListFont.aspx.cs" Inherits="CheckBoxListFont" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="45px" Width="239px">
            <asp:ListItem>Adrotator</asp:ListItem>
            <asp:ListItem>BulletedList</asp:ListItem>
            <asp:ListItem>Button</asp:ListItem>
            <asp:ListItem>CheckBox</asp:ListItem>
        </asp:CheckBoxList>
        <br />
        <asp:Button ID="Button1" runat="server" Height="35px" onclick="Button1_Click"
            Text="Change forecolor" Width="119px" />
   
    </div>
    </form>
</body>

</html>
Codebehind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CheckBoxListFont : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBoxList1.ForeColor = System.Drawing.Color.Red;


    }
}
Output
Programmatically change CheckBoxList text color in ASP.NET

Programmatically change CheckBoxList text color in ASP.NET

Programmatically change CheckBoxList font size in ASP.NET

Introduction

If you want to change size of the font for better visibility then you must change font size according to users. Highly rich content website change font color , font name/face and font size according to users. Get lots of visitors or viewers from your website  using website functionality (better presentation, better look and better theme) .

lets take an simple example


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckBoxListFont.aspx.cs" Inherits="CheckBoxListFont" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="45px" Width="239px">
            <asp:ListItem>Adrotator</asp:ListItem>
            <asp:ListItem>BulletedList</asp:ListItem>
            <asp:ListItem>Button</asp:ListItem>
            <asp:ListItem>CheckBox</asp:ListItem>
        </asp:CheckBoxList>
        <br />
        <asp:Button ID="Button1" runat="server" Height="35px" onclick="Button1_Click"
            Text="Change Font" Width="119px" />
   
    </div>
    </form>
</body>

</html>

Codebehind Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CheckBoxListFont : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBoxList1.Font.Size = FontUnit.Larger;

    }
}
Output
Programmatically change CheckBoxList font size in ASP.NET

Programmatically change CheckBoxList font size in ASP.NET

Friday, November 1, 2013

How to Access Record by DataGridViewButton: Windows Forms

I have created a DataGridViewButton for each particular record of DataGridView, as in my earlier post. Adding a button is not sufficient in programming, it should perform some functions when clicked, so we have to generate its click event.

In simple words, we can’t generate a click event of this DataGridViewButton using double click or from the events section. As this is in datagridview so generate Cell_Click event of this datagridview. Now, I have added this button in first column, so I can check it on the same.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("Column: " + e.ColumnIndex + " and Row: " + e.RowIndex);
}

By this simple code, the debugger will execute all your line of code, written in the space provided. ColumnIndex contains the column index and RowIndex contains row index, when this event triggered.

Let suppose, we want to access the record of the clicked row of datagridview. I have bound that datagridview with list of student class, so the following C# lines of code will get the instance of student, which is currently focused by mouse click event.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
Student stu = dataGridView1.Rows[e.RowIndex].DataBoundItem as Student;
MessageBox.Show("Name: " + stu.Name + "\r" + "Age: " + stu.Age
+ "\r" + "City" + stu.City + "\r"
+ "Dob: " + stu.Dob);
}

The first line will get the particular record, which is of student type. When we run the project and click on the datagridviewbutton it will show a message box, containing the detail of particular student.

How to access record by Datagridviewbutton in C#: Windows Forms

© Copyright 2013 Computer Programming | All Right Reserved