我正在编写一个xml文件以发布到OTA API 如果我用字符串或文件写它,我会看到输出的差异。 如果我用字符串写它,我会看到不同的编码 看起来我写字符串设置时不起作用。 有帮助吗? 我简化代码放置2个按钮按钮2写入文件一个按钮3在字符串中。你看代码是一样的。 有什么建议吗? THX
文件中的输出按钮2 第一行
?xml version="1.0" encoding="UTF-8" standalone="true"?>
字符串
中的输出按钮3?xml version="1.0" encoding="utf-16" standalone="yes"?>
码
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