网站地图    收藏   

主页 > 前端 > css教程 >

XSL和XML转换为HTML文件 - html/css语言栏目:html.cs

来源:自学PHP网    时间:2015-04-14 14:51 作者: 阅读:

[导读] 1/// summary2 /// XSL和XML转换为HTML文件3 /// /summary4 /// param name=strXSLTextXSL模板文件/param5 /// param name=strXMLXML模板文件/param6 /// returnsHTML的tring/r......

 1/// <summary>
 2 /// XSL和XML转换为HTML文件
 3 /// </summary>
 4 /// <param name="strXSLText">XSL模板文件</param>
 5 /// <param name="strXML">XML模板文件</param>
 6 /// <returns>HTML的tring</returns>
 7 private static SmcErr GetEmailBodyContent(string strXSLText, string strXML, out string strHTML)
 8 {
 9 SmcErr err = new SmcErr(SmcErr.SMC_ERR_SUCCESS);
10 strHTML = null;
11 if (string.IsNullOrEmpty(strXSLText) || string.IsNullOrEmpty(strXML))
12 {
13 err.SetErrorNo(SmcErr.ERR_EMAIL_PARAMNULL);
14 return err;
15 }
16 // Load the style sheet.
17 XslCompiledTransform xslt = new XslCompiledTransform();
18 //Instance the StringBuilder to return value
19 StringBuilder sb = new StringBuilder();
20 //Execute the XmlWriter.Create and output the xmlWriter
21 XmlWriter xmlWriter = null;
22 XmlReader xslReader = null;
23 XmlReader xmlReader = null;
24 try
25 {
26 xmlWriter = XmlWriter.Create(sb);
27 //Execute the Encoding and output the byte[]
28 byte[] bXSL = System.Text.Encoding.UTF8.GetBytes(strXSLText);
29 //Execute the XmlReader.Create and output the xslReader
30 xslReader = XmlReader.Create(new MemoryStream(bXSL));
31
32 //Execute the Encoding and output the byte[]
33 byte[] bXML = System.Text.Encoding.UTF8.GetBytes(strXML);
34 //Execute the XmlReader.Create and output the xslReader
35 xmlReader = XmlReader.Create(new MemoryStream(bXML));
36
37 //Load the style sheet.
38 xslt.Load(xslReader);
39 //Execute the transform and output the results to xmlWriter.
40 xslt.Transform(xmlReader, null, xmlWriter);
41
42 strHTML = sb.ToString();
43 }
44 catch (Exception ex)
45 {
46 err.SetErrorNo(SmcErr.ERR_EMAIL_PARAMNULL);
47 return err;
48 }
49 finally
50 {
51 xslReader = null;
52 xmlReader = null;
53 }
54
55 if (strHTML == null)
56 {
57 err.SetErrorNo(SmcErr.ERR_EMAIL_PARAMNULL);
58 }
59
60 return err;
61
62 }
63
64 #endregion

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论