• 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

    作者:chhuic

    出处:http://chhuic.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    Java中间件:淘宝网系统高性能利器(转)
    淘宝的数据库拆分(TDDL)(转)
    java web几种开发模式(转)
    C++模板【转】
    set[c++]
    C# jsonhelper
    Vector[C++]
    list[C++]
    map[C++]
    C[泊车管理系统]
  • 原文地址:https://www.cnblogs.com/chhuic/p/2111529.html
Copyright © 2020-2023  润新知