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

转载于:https://www.cnblogs.com/chhuic/archive/2011/07/20/2111529.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值