开发者

Is there a "syntactic sugar" way to escapte XML attributes values without String.replace?

开发者 https://www.devze.com 2023-03-18 07:44 出处:网络
From the XML specs... To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号