Matt Mencel
Matt Mencel

Reputation: 285

How to tell Java which StringEscapeUtils.escapeXML() to use?

I'm trying to use the StringEscapeUtils.escapeXML() function from org.apache.commons.lang...

There are two versions of that function, one which expects (Writer, String) and one which just expects (String)....

http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html#escapeXml(java.lang.String)

I'm trying to use the version that just expects the String parameter without the Writer, but Java is complaining that I've not given it a Writer.

How do I use this in my program so that I don't need a Writer?

String escXml = StringEscapeUtils.escapeXml(attr.get());
xml = xml.concat("<"+attr.getID()+">"+escXml+"</"+attr.getID()+">");

I've also tried just doing it inline in the string itself.

xml = xml.concat("<"+attr.getID()+">"+StringEscapeUtils.escapeXml(attr.get())+"</"+attr.getID()+">");

Both of these attempts have given me the error about it expecting the Writer though. Can anyone help me with this?

Thanks, Matt

Upvotes: 3

Views: 6724

Answers (3)

kapil nadiyapara
kapil nadiyapara

Reputation: 221

You should compile the java class with the specify version if you have install the more than one version of java in you system.

You should compile your file using this way.

javac -target -source

E.g H:>javac -target 1.6 -source 1.6 Testt.java

So your target and Source version is tell to the java so it will call the particular version class at run time..

Upvotes: 2

matt b
matt b

Reputation: 139931

The error message is telling you that you are passing an Object into the method, not a String.

If you are sure that the Object is a String, then you'll need to cast it to a String first.

If this doesn't work, please post the actual code that is giving you trouble.

Upvotes: 6

Michael Borgwardt
Michael Borgwardt

Reputation: 346310

What exactly is the compiler error message?

is it possible that you're using a different version of the commons library that does not have the 1-parameter method?

Upvotes: 0

Related Questions