Reputation: 435
Well, the subject says it all really. How to insert data XML via XSLT to MySQL database in net 4 C# ?
I have a few jobs that I could write C-sharp to transform the xml into insert, however, I would prefer to use XSLT and learn as I go.
My code behind:
protected void Page_Load(object sender, EventArgs e)
{
string xmlsrc = "http://.../News.rss";
string Password = "ABC";
string UserAccount = "123";
string DomainName = "XYZ";
string xslsrc = "RSS91.xslt";
if (xmlsrc != "")
{
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(xmlsrc);
if (UserAccount != "")
{
wr.Credentials = new NetworkCredential(UserAccount, Password, DomainName);
}
wr.Timeout = 10000;
WebResponse resp = wr.GetResponse();
Stream stream = resp.GetResponseStream();
XmlTextReader reader = new XmlTextReader(stream);
reader.XmlResolver = null;
XmlDocument doc = new XmlDocument();
doc.Load(reader);
xmlRSS.Document = doc;
}
xmlRSS.TransformSource = xslsrc;
}
My XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:param name="title"/>
<xsl:template match="rss">
<xsl:for-each select="channel/item">
<br>
<strong>
<a href="{link}" target="_main">
<xsl:value-of select="title"/>
</a>
</strong>
<br></br>
<xsl:value-of select="description" disable-output-escaping="yes"/>
</br>
<br></br>
<xsl:value-of select="pubDate"/>
<br></br>
</xsl:for-each>
</xsl:template>
<xsl:template match="description">
<br>
<xsl:value-of select="."/>
</br>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0
Views: 2563
Reputation: 3902
XSLT
is a language to transform xml to either xml, text or HTML (all text for that matter). It's not meant to connect to databases. You would either need to do this in your code, e.g. C# or use a xslt extention that is supported by the xslt processor. I think Saxon has this ability - The Saxon SQL Extension. This requires you to use Saxon, which is written in Java. There is a .net version also.
Upvotes: 1