简体   繁体   中英

Special Character and html tag parsing in xml

I have an xml in which it contails <br/> tag in the element data fiels. I am able to parse it using string builder in Sax parser. Now i want to trim down some of the tags and return back an xml response. In the response xml source i am getting the tag replaces as &lt;br/> . My concern is that the "<" gets replaced by &lt; but the ">" tag does not get replaced by &gt; . Anybody has idea of how to sort out this problem.

You should escape for XML. Try EscapeUtils from Apache Commons Lang .

Mind that also Java may be having trouble dealing with it.

I prefer first to escapeJava and after that escapeXML.

Usage:

    String escapedStr= StringEscapeUtils.escapeJava(yourString);
    escapedStr= StringEscapeUtils.escapeXML(yourString);

Apache Commons Lang download link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM