扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
using System.Data.OleDb; using System.Xml; |
private string strConn ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + " C:\\Program Files\\Microsoft Office\\Office10\\Samples\\" + "Northwind.mdb;"; |
//Connect to the data source. OleDbConnection objConn = new OleDbConnection (strConn); try { objConn.Open(); //Fill a dataset with records from the Customers table. OleDbCommand objCmd = new OleDbCommand( "Select CustomerID, CompanyName, ContactName, " + "Country, Phone from Customers", objConn); OleDbDataAdapter objAdapter = new OleDbDataAdapter(); objAdapter.SelectCommand = objCmd; DataSet objDataset = new DataSet(); objAdapter.Fill(objDataset); //Create the FileStream to write with. System.IO.FileStream fs = new System.IO.FileStream( "C:\\Customers.xml", System.IO.FileMode.Create); //Create an XmlTextWriter for the FileStream. System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter( fs, System.Text.Encoding.Unicode); //Add processing instructions to the beginning of the XML file, one //of which indicates a style sheet. xtw.WriteProcessingInstruction("xml", "version='1.0'"); //xtw.WriteProcessingInstruction("xml-stylesheet", // "type='text/xsl' href='customers.xsl'"); //Write the XML from the dataset to the file. objDataset.WriteXml(xtw); xtw.Close(); //Close the database connection. objConn.Close(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <HTML> <HEAD> <STYLE> .HDR { background-color:bisque;font-weight:bold } </STYLE> </HEAD> <BODY> <TABLE> <COLGROUP WIDTH="100" ALIGN="CENTER"></COLGROUP> <COLGROUP WIDTH="200" ALIGN="LEFT"></COLGROUP> <COLGROUP WIDTH="200" ALIGN="LEFT"></COLGROUP> <COLGROUP WIDTH="100" ALIGN="LEFT"></COLGROUP> <COLGROUP WIDTH="100" ALIGN="LEFT"></COLGROUP> <TD CLASS="HDR">Customer ID</TD> <TD CLASS="HDR">Company</TD> <TD CLASS="HDR">Contact</TD> <TD CLASS="HDR">Country</TD> <TD CLASS="HDR">Phone</TD> <xsl:for-each select="NewDataSet/Table"> <TR> <TD><xsl:value-of select="CustomerID"/></TD> <TD><xsl:value-of select="CompanyName"/></TD> <TD><xsl:value-of select="ContactName"/></TD> <TD><xsl:value-of select="Country"/></TD> <TD><xsl:value-of select="Phone"/></TD> </TR> </xsl:for-each> </TABLE> </BODY> </HTML> </xsl:template> </xsl:stylesheet> |
xtw.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='customers.xsl'"); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者