Chevy Mark Sunderland

Chevy Mark Sunderland

  • 2k
  • 188
  • 159.8k

[C# net4] Insert in DB the values of xslt file

Mar 20 2014 4:46 AM
I need insert in DB the values of xslt file and I tried this code.

The insert in DB is executed but for only first row of xsl file.

I would greatly appreciate any help you can give me in working this problem, thank you.

code behind file:

XmlTextReader reader = new XmlTextReader(stream);
reader.XmlResolver = null;

XmlDocument doc = new XmlDocument();

xmlRSS.XPathNavigator = doc.CreateNavigator();

XmlNodeList dataNodes = doc.SelectNodes("rss");

OdbcCommand command;
OdbcDataAdapter adpter = new OdbcDataAdapter();

foreach (XmlNode node in dataNodes)
string title = node.SelectSingleNode("//title").InnerText;
string description = node.SelectSingleNode("//description").InnerText;
string pubDate = node.SelectSingleNode("//pubDate").InnerText;
string sql = "insert into Product (title, description, pubdate) values ('" + title.ToString() + "', '" + description.ToString() + "', STR_TO_DATE('" + pubDate.ToString() + "', '%a, %d %b %Y %H:%i:%s GMT'));";

command = new OdbcCommand(sql, connection);
adpter.InsertCommand = command;
xslt file

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
<xsl:output method="html" indent="yes"/>
<xsl:param name="title"/>
<xsl:template match="rss">
<xsl:for-each select="channel/item">
<a href="{link}" target="_main">
<xsl:value-of select="title"/>
<xsl:value-of select="description" disable-output-escaping="yes"/>
<xsl:value-of select="pubDate"/>
<xsl:template match="description">
<xsl:value-of select="."/>