SELECT TOP 10 * FROM dbo.UserInfo
FOR XML PATH('UserInfo'),ROOT ('UserList')
就会生成以下XML
PATH里面的字符串生成行标签
ROOT生成根标签
<UserList>
<UserInfo>
<UserName>administrator</UserName>
<Age>21</Age>
<NickName>小张</NickName>
......
</UserInfo>
<UserInfo>
<UserName>administrator</UserName>
<Age>21</Age>
<NickName>小张</NickName>
......
</UserInfo>
<UserInfo>
<UserName>administrator</UserName>
<Age>21</Age>
<NickName>小张</NickName>
......
</UserInfo>
......
</UserList>
你可以先把Excel中的数据读取到DataSet中,然后DataSet直接Save为Xml文件即可。123456789101112131415DataSet ds = new DataSet()OleDbCommand excelCommand = new OleDbCommand()OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter()string excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" + filelocation + "Extended Properties=""Excel 8.0HDR=YesIMEX=1"""OleDbConnection excelConn = new OleDbConnection(excelConnStr)excelConn.Open()DataTable dtPatterns = new DataTable()excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn)excelDataAdapter.SelectCommand = excelCommandexcelDataAdapter.Fill(ds, "Customers")// Get a StreamWriter objectStreamWriter xmlDoc = new StreamWriter("Customers.xml")// Apply the WriteXml method to write an XML documentds.WriteXml(xmlDoc)xmlDoc.Close()
呵呵,你的问题很可爱。XML本身就没有打开方式。一般我们打开XML会用记事本。你如果是指用DW方式打开的话也行。-------------------------------------------------其实不管你以什么方式打开。对那个文件鼠标右击--打开方式(H)--选择程序,进入以后找到你想要的打开方式,在确定之前,你记得把那个钩给勾上。就可以了。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)