I use the following code to create an XML string:
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim tw As New StringWriter
Dim xml As New XmlTextWriter(t w)
xml.WriteStartD ocument()
xml.WriteStartE lement("StartEl ement")
xml.WriteElemen tString("Elemen tString", "TheElement ")
xml.WriteEndEle ment()
xml.WriteEndDoc ument()
xml.Close()
MsgBox(tw.ToStr ing)
End Sub
This produces
<?xml version="1.0" encoding="utf-16"?>
<StartElement >
<ElementString> TheElement</ElementString>
</StartElement>
I need the encoding to say "utf-8", but I can't get it to work.
among other things, I've tried adding
xml.Settings.En coding = New UTF8Encoding(Fa lse)
directly after Dim'ing the xml object, but it throws the "Object reference
not set to an instance" error.
Need some guidance on this one.
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim tw As New StringWriter
Dim xml As New XmlTextWriter(t w)
xml.WriteStartD ocument()
xml.WriteStartE lement("StartEl ement")
xml.WriteElemen tString("Elemen tString", "TheElement ")
xml.WriteEndEle ment()
xml.WriteEndDoc ument()
xml.Close()
MsgBox(tw.ToStr ing)
End Sub
This produces
<?xml version="1.0" encoding="utf-16"?>
<StartElement >
<ElementString> TheElement</ElementString>
</StartElement>
I need the encoding to say "utf-8", but I can't get it to work.
among other things, I've tried adding
xml.Settings.En coding = New UTF8Encoding(Fa lse)
directly after Dim'ing the xml object, but it throws the "Object reference
not set to an instance" error.
Need some guidance on this one.
Comment