views:

13

answers:

1

Hi there,

I've got an .asp page scripted as an xml page, but i'm having some issues with html entities. I have a feed with products and obviously a product description.

The following person of code correctly formats '&' as '&' but I also need to catch instances of the registered mark and make that into the html entity.

Dim varOrgText, varDisplayText
If (rsproducts.Fields.Item("prod_description").Value) <> "" Then
varOrgText = (rsproducts.Fields.Item("prod_description").Value) 
varFormattedOrgText = (Replace(varOrgText, "&", "&amp;"))
varDisplayText = "<![CDATA[" & varFormattedOrgText & "]]>"
End If

I tried doing this to catch the ampersand and registered marks;

Dim varOrgText, varDisplayText
If (rsproducts.Fields.Item("prod_description").Value) <> "" Then
varOrgText = (rsproducts.Fields.Item("prod_description").Value) 
varFormattedOrgText = (Replace(varOrgText, "&", "&amp;"))
varFormattedOrgText2 = (Replace(varOrgText, "®", "&#174;"))
varDisplayText = "<![CDATA[" & varFormattedOrgText2 & "]]>"
End If

But obviously it didn't work, so i'm looking for an easier way of formatting the description.

Would be grateful for any help to make this a bit easier. :)

Thank you.

A: 

You have a little bug in your code: you are replacing the registered mark in varOrgText, not in the varFormattedOrgText

Dim varOrgText, varDisplayText
If (rsproducts.Fields.Item("prod_description").Value) <> "" Then
  varOrgText = (rsproducts.Fields.Item("prod_description").Value) 
  varFormattedOrgText = (Replace(varOrgText, "&", "&amp;"))
  varFormattedOrgText2 = (Replace(varFormattedOrgText, "®", "&#174;"))
  varDisplayText = "<![CDATA[" & varFormattedOrgText2 & "]]>"
End If

Besides that you can try to use server.HTMLEncode() to enconde all HTML, but I think that is not necessary between a <![CDATA[]]> block.

Eduardo Molteni