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

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

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

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

I am trying to use a version that just expects a String parameter without Writer, but Java complains that I did not give it a Writer.

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

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

I also tried just doing it inline in the line itself.

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

Both of these attempts gave me an error in this expectation of the writer. Can anyone help me with this?

Thanks Matt

+3
source share
3 answers

The error message tells you that you are passing an object to a method, not a string.

If you are sure that the object is a string, you need to first wrap it in a string.

If this does not work, send the actual code that is not pleasant to you.

+6
source

You must compile the java class with the specified version if you have installed more than one version of java on your system.

You must compile the file this way.

javac -target -source

For example, H:> javac -target 1.6-source 1.6 Testt.java

So, your target and source versions are reporting java, so it will call a specific version class at runtime.

+2
source

What is a compiler error message?

Is it possible that you are using a different version of the commons library that does not have a method with 1 parameter?

0
source

All Articles