From the XML specs...
To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as "
'
", an开发者_运维技巧d the double-quote character (") as ""
".
Is there a standard or easier way to do it rather than using string find / replace? (apache commons?)
The best way is to use an XML API instead of trying to do it all through string manipulation, to be honest.
There are so many little things you could easily get wrong - why not use a purpose-built API?
I agree with Jon Skeet. If you really have no choice, consider using StringEscapeUtils.escapeXml from commons-lang.
精彩评论