I am trying to download xml file with having some issue with special character. It load successfully in XmlDocument but get the error while transfer 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
CodePudding user response:
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