-
Dec 8th, 2020, 01:33 PM
#1
Thread Starter
Addicted Member
xml encoding
I have written a program that creates an xml using the following code
Code:
Dim writer As New XmlTextWriter(SaveFile, System.Text.Encoding.UTF8)
writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 5
writer.WriteStartElement("Table")
I need iso-8859-1 encoding however it is apparently not an option, with this method.
How can I create the encoding that I need?
I am using VB 2019
Thank You
-
Dec 8th, 2020, 02:20 PM
#2
Re: xml encoding
I haven't tested it, but you should be able to specify any encoding in the second argument of the constructor:
Code:
Using writer = New XmlTextWriter(SaveFile, Encoding.GetEncoding(28591))
With writer
.WriteStartDocument(True)
.Formatting = Formatting.Indented
.Indentation = 5
.WriteStartElement("Table")
End With
End Using
Edit - As I thought, it is possible. Take a look at this fiddle: https://dotnetfiddle.net/e0DXIA
Last edited by dday9; Dec 8th, 2020 at 02:25 PM.
-
Dec 8th, 2020, 03:01 PM
#3
Re: xml encoding
As a test I used a literal. Make certain that the encoding is what you want!
Code:
Dim libraryRequest As XDocument
libraryRequest = <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<!-- Tests that the application works. -->
<books>
<book/>
<foo>
<!-- the characters in bar will not be stored with ISO-8859-1 -->
<bar>■▲</bar>
</foo>
</books>
libraryRequest.Save("path here")
-
Dec 8th, 2020, 08:37 PM
#4
Thread Starter
Addicted Member
Re: xml encoding
I modified the first line as shown below and it works now.
Code:
Dim writer As New XmlTextWriter(SaveFile, System.Text.Encoding.GetEncoding(28591))
When I tried using dday9's code I received and error that the writer had not been declared, but it put me on the right track.
Thank You
-
Dec 8th, 2020, 11:34 PM
#5
Lively Member
Re: xml encoding
Dim Stream As New IO.StreamReader("File.xml", System.Text.Encoding.UTF8)
Dim Reader As New Xml.XmlTextReader(Stream)
Reference : https://stackoverflow.com/a/17528811/11954917
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|