Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML Entities 1

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,965
US
Hi,

I am writing XML files out and wondered if something like this is the best solution for my issue. I am getting a lot of data that has Spanish characters, etc... and it is causing the XML parser to fail that is ingesting my files.

Basically, should I keep adding *Replace* lines below for all entries on this page?


Thanks.

Code:
Public Function HTMLEEntititesCode(p_strText as String) as String

Dim strTemp as String
  strTemp = p_strText

  strTemp = Replace(strTemp, "Ó", "ó")
   'repeat the above line

  HTMLEEntititesCode = strTemp 
End Function

Swi
 
>should I keep adding *Replace*

That has always seemed to be the standard approach. And it is irritating that none of the HTML or XML libraries has a built-in method for this.

A slightly lazier approach would be to use the hex codes instead of entity names, in which case something like the following (quickly put together from a couple of sources, so may be missing some characters):

Code:
[COLOR=blue]Public Function EncodeString(ByVal strOriginal As String) As String
    Dim strSpecial As String
    Dim lp As Long
    Dim strResult As String
    Dim strCharList As String
    strCharList = "óáéíúÁÉÍÓÚ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿×÷ÀÂÃÄÅÆÇÈÊËÌÎÏÐÑÒÔÕÖØÙÛÜÝÞßàâãäåæçèêëìîïðñòôõöøùûüýþÿŒœŠšŸƒˆ‘’‚“”„†‡•…‰‹›€™"
    strResult = strOriginal
    For lp = 1 To Len(strCharList)
        strSpecial = Mid(strCharList, lp, 1)
        strResult = Replace(strResult, strSpecial, "&#x" & Hex(AscW(strSpecial)) & ";")
    Next
    EncodeString = strResult
End Function[/color]

 
Eek - just noticed that my post got encoded a bit by tektips...

Need to review...
 
Yep, so the Code tags cause tek-tips to do some 'safe' encryption of special characters. Here's what the string should have looked like

[tt]strCharList = "óáéíúÁÉÍÓÚ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿×÷ÀÂÃÄÅÆÇÈÊËÌÎÏÐÑÒÔÕÖØÙÛÜÝÞßàâãäåæçèêëìîïðñòôõöøùûüýþÿŒœŠšŸƒˆ‘’‚“”„†‡•…‰‹›€™"

[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top