错误“.”,十六进制值 0x00,是从网络路径下载 XML 文件时的无效字符
Error '.', hexadecimal value 0x00, is an invalid character while downloading XML file from a network path
我正在尝试下载 xml 文件,但遇到一些特殊字符问题。它在 XmlDocument 中成功加载,但在传输 XslCompiledTransform()
时出现错误
document = New XmlDocument()
Dim strRecords As String = ''
Dim btBuffer As Byte() = Nothing
If File.Exists(strFilePathXml) Then
Dim fs As FileStream = New FileStream(strFilePathXml, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)
document.Load(fs)
End If
create navigator
navigator = document.CreateNavigator
load style sheet
transformer = New XslCompiledTransform()
If File.Exists(strFilePathXslt) Then
transformer.Load(strFilePathXslt)
End If
transform XML data
output = New StringWriter()
output.WriteLine("<meta charset=""UTF-8"">")
output.WriteLine("<style>.number {mso-number-format:0\.00; } </style>")
. transformer.Transform(navigator, Nothing, output) Getting Exception here
Here is the solution :-
Dim streamReader As StreamReader = New StreamReader(strFilePathXml, Encoding.UTF8)
Dim content As String = streamReader.ReadToEnd()
streamReader.Close()
Dim xmlContent As String = Regex.Replace(content, "�", "", RegexOptions.Compiled)
document.LoadXml(xmlContent)
document.PreserveWhitespace = True
我正在尝试下载 xml 文件,但遇到一些特殊字符问题。它在 XmlDocument 中成功加载,但在传输 XslCompiledTransform()
时出现错误 document = New XmlDocument()
Dim strRecords As String = ''
Dim btBuffer As Byte() = Nothing
If File.Exists(strFilePathXml) Then
Dim fs As FileStream = New FileStream(strFilePathXml, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)
document.Load(fs)
End If
create navigator
navigator = document.CreateNavigator
load style sheet
transformer = New XslCompiledTransform()
If File.Exists(strFilePathXslt) Then
transformer.Load(strFilePathXslt)
End If
transform XML data
output = New StringWriter()
output.WriteLine("<meta charset=""UTF-8"">")
output.WriteLine("<style>.number {mso-number-format:0\.00; } </style>")
. transformer.Transform(navigator, Nothing, output) Getting Exception here
Here is the solution :-
Dim streamReader As StreamReader = New StreamReader(strFilePathXml, Encoding.UTF8)
Dim content As String = streamReader.ReadToEnd()
streamReader.Close()
Dim xmlContent As String = Regex.Replace(content, "�", "", RegexOptions.Compiled)
document.LoadXml(xmlContent)
document.PreserveWhitespace = True