XSL和XML转换为HTML文件
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
相关新闻>>
- 发表评论
-
- 最新评论 更多>>