前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >不小心栽了XML的坑

不小心栽了XML的坑

作者头像
前端黑板报
发布2018-07-24 16:22:14
4870
发布2018-07-24 16:22:14
举报
文章被收录于专栏:前端黑板报前端黑板报

最近在做一个聊天系统,前端用的框架conversejs,传输的数据是用XML格式。在测试和预发布上基本都没有问题,可以正常的得到用户列表。

可是今天上线的时候,遇到几个客服的用户列表不能显示,并且报错:

上面一大串代码,实在头大。可是仔细看看最下面有一行报错提示:uncaught badformat

我Google了一下:

得到如下:

大致就是编码错误,有特殊字符:< 和 & 等。接着我又把最上面的那些XML放到格式化工具里:

得到如上的报错,证明里面确实有 & 符号。我放到一些别的在线工具也没报错:

看来还是得多测试几个格式化工具。

最后我又搜了:xml special character

全部内容如下:

Symbol (name)

Escape Sequence

< (less-than)

&#60; or &lt;

> (greater-than)

&#62; or &gt;

& (ampersand)

&#38;

' (apostrophe or single quote)

&#39;

" (double-quote)

&#34;

以上5个特殊字符:

< 、> 、& 、’ 、"

&lt;

The less-than character (<) starts element markup (the first character of a start-tag or an end-tag).

&amp;

The ampersand character (&) starts entity markup (the first character of a character entity reference).

&gt;

The greater-than character (>) ends a start-tag or an end-tag.

&quot;

The double-quote character (") can be symbolised with this character entity reference when you need to embed a double-quote inside a string which is already double-quoted.

&apos;

The apostrophe or single-quote character (') can be symbolised with this character entity reference when you need to embed a single-quote or apostrophe inside a string which is already single-quoted.

解决方法:

  1. 在服务端回传数据时,过滤掉特殊字符,因为这个昵称在前端页面是不显示的。
  2. 服务端转义上面特殊字符
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-06-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 前端黑板报 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档