Link to home
Start Free TrialLog in
Avatar of SCDMETA
SCDMETA

asked on

Special characters in a Web Service xml response

We have a web service that is using document/literal message encoding.  Several values returned from the web service could contain “special” characters, such as greater than (>) or less than (<).  There are two approaches that I am aware of for dealing with these special characters.  1) Wrap the data in a CDATA section  2) Escape the characters by changing them to &gt; and &lt;.

Are there any other approaches that I missed?

I am wondering if there is a recommended approach to dealing with these special characters.  Do you recommend using CDATA or escaping them?

If CDATA is the recommendation, do you recommend always adding the CDATA section or only adding the CDATA section if the data being transferred contains a “special” character?  This is really a performance question of the overhead of checking for special characters versus transferring and parsing the unneeded CDATA section.
ASKER CERTIFIED SOLUTION
Avatar of dualsoul
dualsoul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SCDMETA
SCDMETA

ASKER

I am going to accept dualsoal's answer for a few reasons.  
1) You were the only one posting a response..for which I thank you.

2) You stated you use a simple filter to replace characters with it's entity escape sequence.
I was looking for some insight in how others handled their data.
We have a lot of text data, that could contain special characters, and I am still concerned about the overhead of escaping every string.
I still appreciate the feed back.

3) You agreed that using CDATA sections allows for faster XML assemble process.
I realized that using CDATA sections would be faster on the server side than escaping the data. This is true because we are assembling the XML data ourselves and it is easy to insert the CDATA character sequence before and after the data.  This would be much faster then scan each string and replacing special charaters with escaped values.

If we decide to use CDATA sections, we will probably CDATA all values instead of searching the values to determine if the actual need CDATA sections or not.
Thanks again.