0

In the older version of "org.apache.commons.lang"(2.6) StringEscapeUtils, there is a method to escapexml by passing an instance of "java.io.Writer" as one of the parameter.

eg: escapeXml(Writer writer, String str)

But, in newer version 3 StringEscapeUtils, no available method accepts an instance of "java.io.Writer" as one of the parameter.

Is there any alternative to use the writer in an indirect way, setup a callback or handler?

Crystal Paladin
  • 559
  • 4
  • 24

1 Answers1

1

All the overloads accepting a Writer have been removed - but instead, CharSequenceTranslator instances are available, so you could write:

StringEscapeUtils.ESCAPE_XML10.translate(input, writer);

(Personally I'd strongly recommend using an XML-focused API to write XML rather than doing it "somewhat manually" like this, admittedly...)

Jon Skeet
  • 1,261,211
  • 792
  • 8,724
  • 8,929
  • I'm using OracleWebRowSet and it didn't escape the Special characters like ampersand in text content so resorted to Stringutils in commons lang... so before invoking `OracleWebRowSet.writeXml(FileWriter)`, I need to escape it somehow. to avoid xml parse error – Crystal Paladin May 24 '17 at 12:41