[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

Generate XML special characters from Visual Basic 6

Dear Expert:

I'm creating a program made using Visual Basic which generates an XML file. This XML file has some texts in a lot of languages, so it appears special characters (like chinese characters, arabic characters, greek characters, etc....).

I have seen some XML file examples and I've seen that all non-english characters (like stressed vowels, ç or ñ) are coded with #&nnn (where nnn is a number).

My doubt is: does it exists a VB6 function to generate these nnn codes from an Unicode character ?

The charset encoding that uses this XML is UTF-16.

Thank you in advance.
0
gplana
Asked:
gplana
  • 4
  • 4
1 Solution
 
abelCommented:
If you use UTF-16, (or UTF-8) you do not need to have them escaped through #&nnn or #&xnnn. These "escapes" are called numeric entities. In general, you are supposed to use them when you use an encoding that does not support these characters (like Latin-1, ISO-8859-5 or KOI-8 etc). But UTF-16, which is a Unicode encoding, is guaranteed to support all these characters.

Usually, all you need to do is simply write them as a wide character string to the XML file, the same way you are probably already doing.
0
 
gplanaAuthor Commented:
Thank you, but, for any reason, my client wants the XML file with all non-english characters encoded to numeric entities.

Do you know if there is a function in Visual Basic 6 for doing this conversion ?

Thank you.
0
 
abelCommented:
The trick is to use ChrW and AscW. The last one will give you the Wide Character (Unicode) numeric value. A page where it is explained how to deal with Unicode characters in VB6 is here: http://support.microsoft.com/kb/145745
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gplanaAuthor Commented:
So, the value returned by AscW is the number nnn to encode to using the syntax #&nnn ?
0
 
gplanaAuthor Commented:
And is it correct to put higher numbers using this syntax ? I mean, such as #&nnnnn; ?
0
 
abelCommented:
> So, the value returned by AscW is the number nnn to encode to using the syntax #&nnn ?
precisely that!

> And is it correct to put higher numbers using this syntax ? I mean, such as #&nnnnn; ?
also correct ;-)

they won't be higher then 65535 with VB6, because it cannot deal with surrogate pairs (iirc), but that's a very advanced subject and only for Unicode version 4 and higher. VB6 comes from the time of Unicode version 3. But it is still sufficient for almost all cases.
0
 
gplanaAuthor Commented:
Excellent !!! Thank you very much.
0
 
abelCommented:
> Excellent !!! Thank you very much.

you're welcome! Always there to help :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now