I'm creating XML documents with values fetched from a DB. Occasionally due to a legacy implementation, I'll pullback a value that contains a char that's invalid when not properly escaped (& for example).
So the question becomes, should I CDATA or Escape? Are certain situations more appropriate for one vs. the other?
Examples:
<Email>foo&[email protected]</Email>
I'd lean towards CDATA here.
<Name>Bob & Tom</Name>
I'd lean towards escaping here.
I want to avoid blindly CDATA'ing every time, but from a performance perspective it seems like that's the logical choice. That will be always faster than looking for an invalid char, and if it exists then wrap.
Thoughts?