【问题标题】:Create SqlXml object instead of string object创建 SqlXml 对象而不是字符串对象
【发布时间】:2010-01-29 07:57:25
【问题描述】:

我有一个方法:

public static string UnZipStr(byte[] input)
{
    if (input == null){
        return null;
    }
    using (MemoryStream inputStream = new MemoryStream(input))
    using (DeflateStream gzip = new DeflateStream(inputStream, CompressionMode.Decompress))
    using (StreamReader reader = new StreamReader(gzip, System.Text.Encoding.UTF8))
    {
        return reader.ReadToEnd();
    }
}

但我总是得到 xml 文本解压缩,这是事实。 我需要更改此方法以返回 SqlXml 对象。 不幸的是,我是 Java 开发人员,无法解决此任务。

【问题讨论】:

    标签: c# .net


    【解决方案1】:

    您需要 SqlXml 对象还是 XmlDocument/XDocument 对象? This post关于将SqlXml对象转成XmlDocument可能与你的需求有关。

    您可以执行以下操作:

    public static string SqlXmlFromZippedBytes(byte[] input)
    {
        if (input == null){
            return null;
        }
        using (MemoryStream inputStream = new MemoryStream(input))
        using (DeflateStream gzip = new DeflateStream(inputStream, CompressionMode.Decompress))
        using (StreamReader reader = new StreamReader(gzip, System.Text.Encoding.UTF8))
        {
            return new SqlXml(reader); // From System.Data.SqlTypes
        }
    }
    

    这是SqlXml constructor 上的文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 2021-08-11
      • 2011-08-06
      • 2014-02-08
      • 1970-01-01
      • 2015-09-08
      • 2014-11-22
      相关资源
      最近更新 更多