Convert Xml node list to Data table

August 24, 2012

XmlDocument xmldoc = new XmlDocument();
FileStream fs = new FileStream(Application.StartupPath + “\\Response.xml”,FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
fs.Close();
XmlNodeList xmlnode;
xmlnode = xmldoc.GetElementsByTagName(comboBox1.Text.Trim());

//ComboBox1.Text means Xml node Name  Here
if (xmlnode.Count > 0)
{
//DataSet ds = new DataSet();
//ds.ReadXml(Application.StartupPath + “\\Response.xml”);
DataTable dt = ConvertXmlNodeListToDataTable(xmlnode);

//ds.ReadXml(
if (dt != null && dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
}
}

//—-Method for convert xmlnode list to data table
public DataTable ConvertXmlNodeListToDataTable(XmlNodeList xnl)
{
DataTable dt = new DataTable();
int TempColumn = 0;

foreach (XmlNode node in xnl.Item(0).ChildNodes)
{
TempColumn++;
DataColumn dc = new DataColumn(node.Name, System.Type.GetType(“System.String”));
if (dt.Columns.Contains(node.Name))
{
dt.Columns.Add(dc.ColumnName = dc.ColumnName + TempColumn.ToString());
}
else
{
dt.Columns.Add(dc);
}
}

int ColumnsCount = dt.Columns.Count;
for (int i = 0; i < xnl.Count; i++)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < ColumnsCount; j++)
{
dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
}
dt.Rows.Add(dr);
}
return dt;
}

}


How to extract whole number from a string using javascript

August 24, 2012

You’ll surely get your desired Output.

<script language=”javascript”>

var txt = “GUJ 12.50 VAT”;
var numb = txt.match(/\d+./g);
numb = numb.join(“”);
alert(numb);

//You’ll get 12.50 in numb….
</script>