Technology Articles

The science of today is the technology of tomorrow. Browse Technology related articles.

Dot. NET Articles

Browse the Dot.NET technical articles.

Web Design & Development

Browse Web Design & Development Articles which includes Technologies of Drupal, Joomla, CodeIgnitor, JQUERY, CMS, etc.

Health Articles

Browse Health Tips & Articles

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

Thursday, March 11, 2010

How to convert Dictionary List to XElement


XElement represents an XML element. This post will describe about how to convert Dictionary to XML Format.

Assume you want the XML to be in the following format,
<paramlist><param><key>1</key><value>100</value></param><param><key>2</key><value>150</value></param></paramlist>
The Dictionary is having <String, String> Format with Two Entries inside as shown below.
<key, 1>
<value, 100>

Sunday, March 7, 2010

How to load XML File and convert to Dictionary


Assume you have a XML file with the following format.

<paramlist><param><key>1</key><value>100</value></param>
<param><key>2</key><value>150</value></param></paramlist>



Thursday, March 4, 2010

How to Convert Datatable to XML programmatically


Lets assume our requirement is to create a Data Table and convert it to XML format. Use the following block code for your purpose.

DataSet myDS = new DataSet();
DataTable dtMyTable = new DataTable("preview");

DataColumn myCol0 = new DataColumn("facility");
myCol0.DataType = System.Type.GetType("System.String");
myCol0.MaxLength = 256;
myCol0.AllowDBNull = true;

DataColumn myCol1 = new DataColumn("doctype");
myCol1.DataType = System.Type.GetType("System.String");
myCol1.MaxLength = 256;
myCol1.AllowDBNull = true;

dtMyTable.Columns.Add(myCol0);
dtMyTable.Columns.Add(myCol1);
dtMyTable.AcceptChanges();

DataRow myNewRow = dtMyTable.NewRow();
myNewRow["facility"] = "MyFacility Works Great!";
myNewRow["doctype"] = "MyDocType Field Does Too!";
dtMyTable.Rows.Add(myNewRow);
dtMyTable.AcceptChanges();

myDS.Tables.Add(dtMyTable);

myDS.WriteXml(Server.MapPath("~") + "\\sample.xml");