Opt In (Do Not Edit Here)

Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Jun 9, 2015

File Formats: DSV, CSV, XML

DSV - Delimiter Separated Values
  • It stores 2-dimensional arrays of data.
  • It separates the values in each row with specific delimiter charaters.
  • Sometimes first line or record of DSV file is considered as column headers.
  • Most common delimiters used are comma, tab, colon, vertical bar, space.
  • In DSV file, data items are separated by delimiter character.

The file type is known depend on which kind of delimiter is used
  • If delimiter is comma then it is CSV (Common Separated Values) file.
  • If delimiter is tab then it is TSV (Tab Separated Values) file etc.
Mostly double quote ("") are used to enclose each field which prevents the delimiter in actual field value from treated as a field separator.

CSV - Comma Separated Values
  • It stores tabular data i.e. numbers and text in plain text format.
  • It is common data exchange format widely used for consumer, business, and scientific applications.
  • In this comma is used as field separator.
  • Each record of CSV file contains one or more fields which are separated by commas.
  • CSV represents sets or sequences of records with identical column fields.
  • CSV can not represent the hierarchical or object-oriented database or the data.
  • File extension is ".csv".
  • MIME type is "text/csv".

srno, name, country
   1, Mayur, India
   2, Neha, India
   3, Jasmin, USA
   4, Ishita, Iran

   "srno", "name", "country"
   "1", "Mayur Dighe", "India"
   "2", "Neha Dixit", "India"
   "3", "Jasmin Robert", "USA"
   "4", "Ishita S.", "Iran"

XML - eXtensible Markup Language
  • XML is case sensitive markup language.
  • It is a textual data format which emphasize simplicity, generality and usability across the Internet.
  • It is widely used to represent arbitrary data structures.
  • XML document is a string of characters.
  • It contains start-tags and end-tags for each data item
  • start-tag is similar to <section>
  • end-tag is similar to </section>
  • File extension is ".xml".
  • MIME Type is "text/xml" and "application/xml".

<?xml version="1.0" encoding="UTF-8"?>
             <name>Mayur</name>              <country>India</country>

             <srno>2</srno>              <name>Neha</name>              <country>India</country>

             <srno>3</srno>              <name>Jasmin</name>              <country>USA</country>

             <srno>4</srno>              <name>Ishita</name>              <country>Iran</country>

Note: In next blog posts, I show you how to convert CSV file into other delimited file, and CSV to XML conversion. 

Dec 30, 2013

ComboBox - DataGridView Sample

            The Article Demonstrate the how to change the DataSource Property of DataGridView Dynamically.

  • ComboBox Control
  • DataGridView Control

  • The method is so easy to handle.
  • Here, I am taken an XML file as DataBase file.
  • The Article shows displaying data into DataGridView Control of table name selected from the ComboBox Control.

  • Create a new instance of the System.Data.DataSet class.

              DataSet Dset = new DataSet();
Listing 1

  • Now, on the Form_Load event handler read an XML file using DataSet Object.

Listing 2

  • Then add all the TableName avail in the DataSet Object to the ComboBox items collection. Result is displayed in Figure 1.
                for (int item=0; item < Dset.Tables.Count;item++ )
Listing 3


 Figure 1

  • After this, set the DataSource property of DataGridView to the selected item of ComboBox.

                   private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
                             dataGridView1.DataSource = null;
                             dataGridView1.DataSource = Dset.Tables[comboBox1.Text];
Listing 4

Output: Following snapshots shows the intended result.

Figure - 2
Figure 2

Figure -3
Figure 3

          In this session, we have seen the ComboBox – DataGridView operation for displaying table data dynamically from the selected item of ComboBox Control.

Jan 12, 2013

Populating TreeView Control from XML file

The blog post demonstrates how to populate TreeView Control using XML file in C#.NET.

The TreeView control has a Nodes collection with root TreeNode objects. Each TreeNode in turn has its own Nodes collection that holds more than one child TreeNode.

<TreeNode object>.Nodes.Add (TreeNode node) method adds a new TreeNode element with a specified text to the end of the current TreeNode collection.

Step 1: Variables Declaration
DataSet set = new DataSet();  //To store Tables from XML Document

TreeNode parent;              //store Main Table Names
TreeNode child;               //store Contents of Main Table
Listing 1

Step 2: XML file contents tables as shown in below format.
      <Customer CustID="202" Name="Pratik Ghanwat" Contact="8657413501"/>
      <Customer CustID="203" Name="Sohan Dal"      Contact="9746292005"/>
      <Customer CustID="204" Name="Sujit Dalvi"    Contact="8855572178"/>
      <Customer CustID="205" Name="Sushant Shinde" Contact="9835621704"/>
            <Customer CustID="206" Name="Amey Kulkarni"  Contact="9845671203"/>
Listing 2

Step 3: Now retrieve the values from XML File and add it to the Nodes Collection of TreeView Control.
//Read Contents of XML Document

for (int i = 0; i < set.Tables.Count; i++) 
      //Get the Name of Main Table
      parent = treeView1.Nodes.Add(set.Tables[i].TableName);

      //Get Contents of Main Table
      for (int j = 1; j < set.Tables[i].Rows.Count; j++) 
                    child = parent.Nodes.Add(set.Tables[i].Rows[j][2].ToString());
Listing 3

Intended Result:

Figure 1: Output


In this writing, we learned how to populate content from XML file to TreeView Control in C#.


All Rights Reserved. 2014 Copyright SIMPLITONA

Powered By Blogger | Published By Gooyaabi Templates Designed By : BloggerMotion