Abhij
Abhij

Reputation: 1272

Escaping special XML characters in strings

I am creating an input xml to database procedure which i am creating manually through

StringBuilder.append();

finally when all my xml is created i am converting StringBuilder to string by

stringBuilder.tostring()

now the problem is i am getting &(ampersand) in string which i am giving input to oracle\n stored procedure i have also replaced ampersand by

stringUtils.remove(string,'&')

but still oracle stored procedure is giving error for & (ampersand)

i want ask that is any character is getting converted to "ampersand character" in my string like

¢ > < " ÷ 

Upvotes: 1

Views: 2930

Answers (2)

Roger F. Gay
Roger F. Gay

Reputation: 1971

You can include all of XML's special characters ('&','<','>',''','"') in XPL. The XPL to XML conversion utilities will handle everything for you. http://hll.nu

Upvotes: 0

Michael Berry
Michael Berry

Reputation: 72369

You shouldn't really be building XML by hand at all - it's error prone and pretty much reinventing the wheel. For ongoing development I'd seriously consider a dedicated XML library.

However, if you want to quickly escape such characters look to the Apache Commons Lang library:

org.apache.commons.lang.StringEscapeUtils.escapeXml("Here is data & containing special <chars>");

Upvotes: 4

Related Questions