Friday, June 22, 2018

dataset to xml encoding = "UTF-8"

Hi,

While writing dataset to generate XML file with encoding UTF-8, it will not work if you directly use following line of code:

xmlDS.WriteXml(fileName)

It need little more work:

Public Sub WriteXml(ByVal ds As DataSet, ByVal fileName As String, ByVal encoding As Encoding)
    Using writer = XmlWriter.Create(fileName, New XmlWriterSettings With {
        .Encoding = encoding,
        .Indent = True
    })
        ds.WriteXml(writer)
    End Using
End Sub


HTH

No comments: