Escaping XML with Sed

There are five XML characters that need to be escaped:

"   "
'   '
<   &lt;
>   &gt;
&   &amp;

And here is the solution ruakh provided over on stackoverflow

sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'
This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published.