Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VB.net将二进制数据转换为XML_Xml_Vb.net_Binary_Compression_Deflatestream - Fatal编程技术网

使用VB.net将二进制数据转换为XML

使用VB.net将二进制数据转换为XML,xml,vb.net,binary,compression,deflatestream,Xml,Vb.net,Binary,Compression,Deflatestream,我试图从SQL中检索VARBINARY列,然后将二进制数据转换为XML。我可以轻松地检索数据并将其转换为XML,但最近它开始截断转换后的XML文件的最后几个字符。下面是代码和说明 这就是我检索二进制数据的方式 Dim binaryData As Byte() sqlData.Open() binaryCMD.CommandText = "select photo from dbo.testing_filestream where clientName = '" &

我试图从SQL中检索VARBINARY列,然后将二进制数据转换为XML。我可以轻松地检索数据并将其转换为XML,但最近它开始截断转换后的XML文件的最后几个字符。下面是代码和说明

这就是我检索二进制数据的方式

Dim binaryData As Byte()
sqlData.Open()
        binaryCMD.CommandText = "select  photo from dbo.testing_filestream where clientName = '" &   clientSelected1 & "' and date = '" & minimumDate & "'"
        binaryCMD.CommandType = CommandType.Text
        binaryCMD.Connection = sqlData
        binaryData = binaryCMD.ExecuteScalar
然后,我将其转换为MemoryStream

Dim xmlStream As New IO.MemoryStream(binaryData)
            xmlStream.Seek(0, 0)
然后,我将其解压缩(因为它处于压缩模式)

但是,它会截断xml文件中的最后几个字符。(XMLdataReader只是一个包含文件名的字符串)。下面是截断的结果。我希望它是完整的,因为我想把XML转换成数据表

</DocumentEle
Whereas, it should give this in the format of
</DocumentElement>

始终与IDisposable资源一起使用,以避免此类问题:

Using in_fs = File.OpenRead("abc.xml")
Using out_fs = File.Create("def.cmp")
    Using df_fs = New DeflateStream(out_fs, CompressionMode.Compress)
        in_fs.CopyTo(df_fs)
    End Using
End Using
End Using

Using in_fs = File.OpenRead("def.cmp")
Using out_fs = File.Create("abc2.xml")
    Using df_fs = New DeflateStream(in_fs, CompressionMode.Decompress)
        df_fs.CopyTo(out_fs)
    End Using
End Using
End Using

使用SQL参数,不要对日期值使用字符串。谢谢。我将更改它,但它可以很好地检索数据。我已经将二进制数据导出到一个.cmp文件中,并将其与原始数据进行比较,结果是相同的。它只是截断了XML的最后几个字。你能帮我吗。
Using in_fs = File.OpenRead("abc.xml")
Using out_fs = File.Create("def.cmp")
    Using df_fs = New DeflateStream(out_fs, CompressionMode.Compress)
        in_fs.CopyTo(df_fs)
    End Using
End Using
End Using

Using in_fs = File.OpenRead("def.cmp")
Using out_fs = File.Create("abc2.xml")
    Using df_fs = New DeflateStream(in_fs, CompressionMode.Decompress)
        df_fs.CopyTo(out_fs)
    End Using
End Using
End Using