ASCII encode

Hi,

i have a requirement for ASCII encoding the data with special characters (for eg. <,> etc) in a document to string.Can anyone suggest a solution.

Hello,
It might not be very useful suggestion, but check out the services of pub.report…

Regards.

Hi ,

I have referred services in pub.report package but could not find any clue.I will elaborate my query.

i have a document containing xml data which has certain special characters like <.>,& etc… i need these special characters to be ascii coded.For example < should be converted to < and so on. If you have any idea on this please help.

Thanks,
Sireesha.A

Hello,
Buddy, XML doc contains those characters…
But why you want to ascii code them, they will come as it is, wherever you use…

requirement is to ascii encode those characters and send to partner.

Are you using TN for this, and is the requirement specific…
If no, then there is no need for it, you can directly use routeXML…
If yes, then I have not come across still…but still I have doubt…
It you solve this problem, do write back…please…
Regards

What you are referring to is HTML or XML encoding, not ASCII encoding.

This “encoding” is used so that characters with specific meaning to the HTML/XML parser can distinguish between data and reserved characters used in markup.

“Encoding” entails converting the reserved characters that appear within the data to what are called “character entities”. For example, < is converted to <

Within your FLOW service the typical approach to performing this encoding is to set the “encode” input parameter to true when calling pub.xml:documentToXMLString. This will perform encoding on all fields of the document. Side note: IMO, the default for this input is false but should be true. Callers should always set this to true unless there is a specific reason not to.

Another service that is available is pub.string:HTMLEncode. This can be useful in some scenarios when documentToXMLString is not used.

HTH

Hi Rob,

Thanks for your reply.
I understood that to convert < to < using pub.xml:documentToXMLString service i need to set encode as true i.e HTML encoding.

Instead of HTML encoding , is there any way to ASCII encode the data?If yes, please let me know how to achieve that.

Thanks,
Sireesha.A

hi Sireesha,
Use “pub.string:stringToBytes” and set encoding = “ascii”.
alternatively you should consider using UTF-8 encoding as this is backward compatible with ASCII and can encode wide range of international characters as well.

Can you tell us why you need to ASCII encode?

-regards
DC

“Instead of HTML encoding , is there any way to ASCII encode the data”

These are 2 completely different aspects. If you’re creating XML, you must HTML encode the contents of the XML elements. Using the ASCII charset is not an alternative approach. Characters such as <, >, & are within the ASCII charset–they must be converted to character entities.

I suspect you don’t really need to use ASCII–you should probably use ISO-8859-1. And if you do so, you should set the XML header properly to indicate the charset being used.

As DC asks, what’s driving the desire to use US-ASCII charset?