I am writing an xml file to post to a OTA API I see a difference in the output if I write it in string or in file. If I write it in string I see a different encoding It looks like when I write to string setting is not working. Any help? I simplify code placing 2 buttons button 2 writes in file one button 3 in string. You see codes are the same. Any suggestion? Thx
Output button 2 in file first line
?xml version="1.0" encoding="UTF-8" standalone="true"?>
Output button 3 in string
?xml version="1.0" encoding="utf-16" standalone="yes"?>
code
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim settings As New XmlWriterSettings
Dim nomefile As String
Dim stxmlns As String
stxmlns = "http://www.testconnect.com/EQC/AR/2011/06"
settings.Indent = True ' true stabilisce di andare a capo quando cambi elemento
settings.NewLineOnAttributes = True
settings.Encoding = Encoding.UTF8
nomefile = "C:\documenti\test.xml"
Dim wr As XmlWriter = XmlWriter.Create(nomefile, settings)
wr = creawritertest(wr)
wr.Flush()
MsgBox("OK")
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Dim settings As New XmlWriterSettings
Dim sw As New StringWriter()
Dim stxmlns As String
stxmlns = "http://www.testconnect.com/EQC/AR/2011/06"
settings.Indent = True ' true stabilisce di andare a capo quando cambi elemento
settings.NewLineOnAttributes = True
settings.Encoding = Encoding.UTF8
Dim wr As XmlWriter = XmlWriter.Create(sw, settings)
wr = creawritertest(wr)
wr.Flush()
mess.Text = sw.ToString
End Sub
Private Function creawritertest(wr As XmlWriter) As XmlWriter
Dim stxmlns As String
stxmlns = "http://www.testconnect.com/EQC/AR/2011/06"
wr.WriteStartDocument(True)
wr.WriteStartElement("AvailRateUpdateRQ", stxmlns)
wr.WriteEndElement()
Return wr
End Function