zoukankan      html  css  js  c++  java
  • Strips illegal Xml characters

       1:      // strips illegal Xml characters:
       2:      static public String XmlEncode(String S)
       3:      {
       4:          if (S == null) 
       5:          {
       6:              return null; 
       7:          }
       8:      S = Regex.Replace(S, @"[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD]", "", RegexOptions.Compiled);
       9:          return XmlEncodeAsIs(S);
      10:      }
      11:   
      12:      // leaves whatever data is there, and just XmlEncodes it:
      13:      static public String XmlEncodeAsIs(String S)
      14:      {
      15:          if (S == null) 
      16:          {
      17:              return null; 
      18:          }
      19:      StringBuilder sTmp = new StringBuilder();
      20:      using (StringWriter sw = new StringWriter())
      21:      {
      22:      using (XmlTextWriter xwr = new XmlTextWriter(sw))
      23:      {
      24:          xwr.WriteString(S);
      25:          sTmp.Append(sw.ToString());
      26:          xwr.Flush();
      27:          xwr.Close();
      28:      }
      29:      sw.Close();
      30:      }
      31:      return sTmp.ToString();
      32:  }
  • 相关阅读:
    推荐!国外程序员整理的 PHP 资源大全
    PHPSTORM/IntelliJ IDEA 常用 设置配置优化
    PHPStorm下XDebug配置
    MySQL修改root密码的多种方法
    php 修改上传文件大小 (max_execution_time post_max_size)
    phpstorm8注册码
    Linux提示no crontab for root的解决办法
    网站的通用注册原型设计
    解决mysql出现“the table is full”的问题
    通过php下载文件并重命名
  • 原文地址:https://www.cnblogs.com/aot/p/2259064.html
Copyright © 2011-2022 走看看