This example will show escapes the characters in a String using java, guava XmlEscapers and apache commons StringEscapeUtils.escapeXml. If you are looking to escape data within XML, look at using <![CDATA[ your text here ]]>.
Setup
Straight up Java
Google Guava
Guava XmlEscapers will escaped xml attribute tags value and elements in text or a string.
Apache Commons
Apache commons StringEscapeUtils.escapeXml will escape characters in a String using XML entities and supports the five basic XML entities (gt, lt, quot, amp, apos).