Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

xml

jsp

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

like image 582
Matt Mencel Avatar asked Nov 28 '25 22:11

Matt Mencel


1 Answers

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.

like image 160
matt b Avatar answered Nov 30 '25 11:11

matt b



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!