I have a number of fields that are completed by a user on a form and are then sent to a web service via SOAP. When I build my XML to pass along the user entries, it generally works without issue. However, I'm running into issues in a few cases where the API fails and I know it's related to characters within what the user entered.
Is there a proper way to escape a string to be sent via XML? I've read many threads talk about using htmlspecialchars() and then just as many saying that's bad practice. I also just recently realized that I should probably change the encoding to UTF-8?
I'm sure I will probably get down voted for this post as I admittedly don't have much expertise in XML. Looking for the best practice here so my call to this API is as reliable as possible and sincerely appreciate any guidance.
Here's the XML snippet:
//BUILD FIELD DATA
$xmlStr = "<?xml version=\"1.0\" encoding=\"us-ascii\"?>
<record>
<field Name=\"dateCreated\" Text=\"".$DATE_CREATE."\" />
<field Name=\"purpose\" Text=\"".$PURPOSE."\" />
<field Name=\"comments\" Text=\"".$COMMENTS."\" />
<field Name=\"terms\" Text=\"".$TERMS."\" />
</record>";