0
好吧,主題說的都是真的。 如何通過XSLT將數據XML插入到net 4 C#中的MySQL數據庫?如何通過XSLT將數據XML插入數據庫
我有一些工作,我可以寫C-sharp將 xml轉換爲插入,但是,我更喜歡使用XSLT並隨時瞭解。
我後面的代碼:
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;
}
我的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>