Hi i am converting rss into xml using Datable. First i am reading the rss and converting into DataTable. Datatable is then converting into XML.
try
{
DataTable tbl = new DataTable();
tbl.Columns.Add("id");
tbl.Columns.Add("product_name");
XmlDocument doc = new XmlDocument();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("");
XmlNodeList itemNodes = xmlDoc.SelectNodes("//rss/channel/item");
foreach (XmlNode itemNode in itemNodes)
{
DataRow row = tbl.NewRow();
XmlNode idNode = itemNode.SelectSingleNode("id");
XmlNode product_nameNode = itemNode.SelectSingleNode("product_name");
if (idNode != null && product_nameNode != null)
{
row[0] = idNode.InnerText;
row[1] = product_nameNode.InnerText;
}
tbl.Rows.Add(row);
// tbl.Rows.Add(row);
}
DataSet dataSet = new DataSet("Products");
tbl.TableName = "Product";
dataSet.Tables.Add(tbl);
// Save to disk
dataSet.WriteXml("");
dataSet.Clear();
tbl.Clear();
dataSet.Tables.Remove(tbl);
}
catch (Exception ex)
{
// Console.WriteLine(ex.Message);
// Console.Read();
}
The final XML is like that
<Products>
<Product>
<id>121385</id>
<product_name>ABC</product_name>
<Product>
<Product>
...
<Product>
<Product>
...
<Product>
<Products>
The result is fine but i want to add one more node, i.e totalcount just after the
<totalcount>1000</totalcount>
It should be like that.
<Products>
<totalcount>1000</totalcount>
<Product>
...
<Product>
<Product>
...
<Product>
<Products>
How can i add totalcount element?
No comments:
Post a Comment