首页 > 解决方案 > 如何在 xml 文件中将“实体”更改为“实体”

问题描述

在数据库中,我有一个包含"it's"在字符串中的消息模板,所以当我采用该消息模板并制作 xml 格式时,我得到it's了 xml 标记。

sms.setMessage(createSMS.messageFormatter(sms).getMessage());

tagList = new TagList[4]; 
req.setTaglist(tagList);
tagList[0] = new TagList();
tagList[0].setTagName("OA");
tagList[0].setTagValue(dto.getDaInk());

tagList[1] = new TagList();
tagList[1].setTagName("DA");
sms.setMsisdnTosent(Utilities.appendCountryCode(sms.getMsisdnTosent()));
tagList[1].setTagValue(sms.getMsisdnTosent());    

tagList[2] = new TagList();
tagList[2].setTagName("MESSAGE");
tagList[2].setTagValue(sms.getMessage());

tagList[3] = new TagList();
tagList[3].setTagName(Tags.TONE_ID);
tagList[3].setTagValue(sms.getSongId());

我越来越这样了

<tagData>
      <name>MESSAGE</name>
      <value>Dear customer it&quot;&quot;s a confirmation messege sent to activate  Tune ALLAHUMMA EGHFER LE ABAENA WA OMMAHATENA you just heard Latest,reply with *  to copy the Tune, of artist AL SHEIKH MAHER BIN HAMAD AL MUAIQLY and toneId is 176577,cndtn aply.</value>
</tagData>

但我想,it&quot;&quot;s这被替换为it's

标签: javaxml

解决方案


正如 yash 建议的那样,您可以在编辑之前在 xml 变量上使用 org.apache.commons.lang.StringEscapeUtils:

StringEscapeUtils.unescapeXml(xml);

推荐阅读