473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ISO-8859-1 encoding of an xml string

Hey Guys,

Currently, I am using the below code:

Dim oReqDoc as XmlDocument
Dim requiredBytes As Byte()
requiredBytes =
System.Text.UTF8Encoding.UTF8.GetBytes(oReqDoc.Inn erXml).

Here, I am encoding my xml string in UTF8 format.
I want to convert my code to encode the xml string in 'ISO-8859-1'
format.

Any help is appreciated..

Thx,
Chris

Jul 13 '06 #1
4 8345

Christina wrote:
<snip>
Dim oReqDoc as XmlDocument
Dim requiredBytes As Byte()
requiredBytes =
System.Text.UTF8Encoding.UTF8.GetBytes(oReqDoc.Inn erXml).

Here, I am encoding my xml string in UTF8 format.
I want to convert my code to encode the xml string in 'ISO-8859-1'
format.
<snip>

Use the GetEncoding method of the Encoding class to get a custom
encoding.
Dim oReqDoc as XmlDocument
Dim requiredBytes As Byte()
Dim E As System.Text.Encoding
E = System.Text.Encoding.GetEncoding("ISO-8859-1")
requiredBytes = E.GetBytes(oReqDoc.InnerXml)
HTH,

Branco.

Jul 13 '06 #2
Thanks Branco !!
Thats was helpful. I still have another question.

I made the changes. Now, when I debug the application and check at
location where I posted the xml, Request.contentEncoding has value
System.Text.UTF8Encoding.

1) Is it because of the web.configs default :
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />

2) How can I check that the message is ISO-8859-1 encoded ?

Thanks again..
Chris

Branco Medeiros wrote:
Christina wrote:
<snip>
Dim oReqDoc as XmlDocument
Dim requiredBytes As Byte()
requiredBytes =
System.Text.UTF8Encoding.UTF8.GetBytes(oReqDoc.Inn erXml).

Here, I am encoding my xml string in UTF8 format.
I want to convert my code to encode the xml string in 'ISO-8859-1'
format.
<snip>

Use the GetEncoding method of the Encoding class to get a custom
encoding.
Dim oReqDoc as XmlDocument
Dim requiredBytes As Byte()

Dim E As System.Text.Encoding
E = System.Text.Encoding.GetEncoding("ISO-8859-1")
requiredBytes = E.GetBytes(oReqDoc.InnerXml)
HTH,

Branco.
Jul 13 '06 #3
Christina wrote:
<snip>
I made the changes. Now, when I debug the application and check at
location where I posted the xml, Request.contentEncoding has value
System.Text.UTF8Encoding.

1) Is it because of the web.configs default :
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
Uh, I guess you answered your question...
2) How can I check that the message is ISO-8859-1 encoded ?
Appart from visually inspecting the contents of the generated file in a
binary editor (!!!), I have no idea. ISO-8859-1 has no preamble bytes
as do utf-8 ~ utf-32, so there's no 'mark' you can look for, other than
the distinction between certain char conversions... for instance, utf-8
will turn any char with index above 127 into a two byte sequence, while
Latin 1 will convert such char to a single byte.

Therefore Text.Encoding.UTF8.GetByteCount(ChrW(128)) will return 2,
while Text.Encoding.GetEncoding("iso-8859-1").GetByteCount(ChrW(128))
will return 1... =P

HTH...

Regards,

Branco.

Jul 14 '06 #4

write your xml with a encoded string writer
Imports System.Text
Imports System.IO
Namespace Text
'''<summary>
''' Implementeerd een stringwriter waarbij je zelf de encoding kunt
kiezen
''' de data wordt opgeslagen in een stringbuilder
''' </summary>
Public Class EncodedStringWriter
Inherits StringWriter
'Private property setter
Private _Encoding As Encoding
''' <summary>
''' Initializes a new instance of the <see
cref="T:EncodedStringWriter" /class.
''' </summary>
''' <param name="sb">stringbuilder</param>
''' <param name="Encoding">The encoding.</param>
Public Sub New(ByVal sb As StringBuilder, ByVal Encoding As Encoding)
MyBase.New(sb)
_Encoding = Encoding
End Sub
''' <summary>
'''
''' </summary>
''' <value></value>
''' <doc>
''' <summary>getter voor de string encoding </summary>
''' <returns>de Encoding waarin wordt geschreven </returns>
''' <filterpriority>1</filterpriority>
''' </doc>
Public Overrides ReadOnly Property Encoding() As Encoding
Get
Return _Encoding
End Get
End Property
End Class
End Namespace

USAGE ::::

Mvar_sb = New StringBuilder(500)
Mvar_XMLDoc = New XmlTextWriter(New
Text.EncodedStringWriter(Mvar_sb, Encoding.UTF8))
------ choose your encoding

------'now write xml
Mvar_XMLDoc.Formatting = Formatting.Indented
Mvar_XMLDoc.Indentation = 2
Mvar_XMLDoc.WriteStartDocument()
------omitted

------to get the contents of the xml document
Mvar_sb.ToString

as you see everything is now in the requested encoding also the doctype is
now in the correct encoding
regards

Michel Posseth [MCP]



"Branco Medeiros" wrote:
Christina wrote:
<snip>
I made the changes. Now, when I debug the application and check at
location where I posted the xml, Request.contentEncoding has value
System.Text.UTF8Encoding.

1) Is it because of the web.configs default :
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />

Uh, I guess you answered your question...
2) How can I check that the message is ISO-8859-1 encoded ?

Appart from visually inspecting the contents of the generated file in a
binary editor (!!!), I have no idea. ISO-8859-1 has no preamble bytes
as do utf-8 ~ utf-32, so there's no 'mark' you can look for, other than
the distinction between certain char conversions... for instance, utf-8
will turn any char with index above 127 into a two byte sequence, while
Latin 1 will convert such char to a single byte.

Therefore Text.Encoding.UTF8.GetByteCount(ChrW(128)) will return 2,
while Text.Encoding.GetEncoding("iso-8859-1").GetByteCount(ChrW(128))
will return 1... =P

HTH...

Regards,

Branco.

Jul 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: jrefactors | last post by:
When people say C programming language, they mean ISO C89? The latest C is ISO C99, but I heard this is not commonly used. What's the differences between ISO C89 and ISO C99? Please advise....
22
by: Sensei | last post by:
Hi! I'm looking for useful libraries that are strictly ISO C. Any kind of library, from lists, stacks, to trees, searching tools, sorting tools... really *any* kind. Do you have any idea? :)...
22
by: pemo | last post by:
ISO C does not allow extra ';' outside of a function int n;; int main(void) { .... } Anyone care to enlighten me as to why ISO C does not allow this, but
2
by: John Daly | last post by:
Hope this is the right place to post this. I recently downloaded iso disc imsges, however my new pc did not come with burning software, and i can not find my old discs. I tried to use the Burning...
9
by: Alok | last post by:
Hi, I want to purchase the ISO C++ standard ISO/IEC 14882:2003 specification for reference. The ANSI store sells the PDF or CD-ROM of the document for $30...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
1
by: danikar | last post by:
Is there a way to open a file that is inside of an ISO in python? Say I have an ISO file, danikars.iso and on the iso there is a file called information.txt I want to be able to do something...
11
by: ManicQin | last post by:
Hi, I was about to buy the Standard but then I found this link http://www.usatlas.bnl.gov/~dladams/cpp/INCITS+ISO+IEC+14882-2003.pdf Hmmmm... ... The link seems legit so ... what gives? ...
1
by: scotter86 | last post by:
Hi everyone, I'm trying to "burn","mount" what ever you want to call it, an .iso file to a hard disk partition. What I'm trying to do is get this iso on a partition and boot it much like I would a...
10
by: tvnaidu | last post by:
I am using Three pthread functions below, I got ISO error, then I declared int variable called val123, then I assigned, but still I am getting error, any idea?. also I included pthread.h. compiling...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.