加载xml对象时出现意外的标记ILLEGAL
Unexpected token ILLEGAL when load xml object?
从数据库到字符串的转换
String xml = XMLUtils.marshallToString(list);
sre.getServletRequest().setAttribute("LIST", xml);
和代码JS
var regObject = '${requestScope.LIST}';
当在浏览器中打开时。查看源代码我有错误意外的令牌非法。
var regObject = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>//Unexpected token ILLEGAL
<items>
<item>
<id>ID</id>
<productName>PrdName</productName>
<productLink>LINK</productLink>
<productImage>IMG</productImage>
</item>
</items>';
代码marshaleToString:
JAXBContext jaxb = JAXBContext.newInstance(List.class);
Marshaller mar = jaxb.createMarshaller();
mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
mar.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
StringWriter sw = new StringWriter();
mar.marshal(items, sw);
return sw.toString();
有人知道如何解决这个问题吗?
JavaScript的'
和"
字符串文字中不能有未加注释的换行符,因此会出现错误。(ES2015的回溯模板字符串可以。)
在输出XML时,您需要确保JavaScript字符串文字中任何可能特殊的字符,如'
(因为您使用的是单引号)、换行符和反斜杠,都是前面带有反斜杠的转义符。
例如,你希望你的输出看起来像这样:
var regObject = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
<items>'
<item>'
<id>ID</id>'
<productName>PrdName</productName>'
<productLink>LINK</productLink>'
<productImage>IMG</productImage>'
<something>I''m an example with an apostrophe</productImage>'
<something>I''m an example with a '' (backslash)</productImage>'
</item>'
</items>';
当然,也可以用'n
替换换行符(转义任何现有反斜杠后的):
var regObject = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'n<items>'n<item>'n<id>ID</id>'n<productName>PrdName</productName>'n<productLink>LINK</productLink>'n<productImage>IMG</productImage>'n<something>I''m an example with an apostrophe</productImage>'n<something>I''m an example with a '' (backslash)</productImage>'n</item>'n</items>';
相关文章:
- 未捕获的语法错误:javascript对象上出现意外的标记ILLEGAL
- "未捕获的SyntaxError:意外的令牌ILLEGAL“;当我通过AJAX发送html时
- 获取意外的令牌ILLEGAL JS错误
- jQuery after() uncatch SyntaxError: 意外令牌 ILLEGAL
- 使用节点javascript的意外令牌ILLEGAL
- AngularJS angular.js:12520 SyntaxError:意外的令牌ILLEGAL附属窗口
- Android网络视图”;未捕获的SyntaxError:意外的令牌ILLEGAL“;
- jQuery 1.10未捕获语法错误:意外的令牌ILLEGAL
- PHP调用脚本函数,返回值为Uncaught SyntaxError:意外的令牌ILLEGAL
- Liferay主题脚本错误:未捕获语法错误:意外的标记ILLEGAL
- 未捕获的语法错误:jQuery 字符串中意外的标记 ILLEGAL
- 意外的令牌 ILLEGAL - JavaScript 中的 ckeditor 值
- 获取server.js文件的意外令牌ILLEGAL错误
- 未捕获的SyntaxError:在main.js:4中出现意外的令牌ILLEGAL
- 未捕获的语法错误:意外的标记ILLEGAL-一个简单的字符串语法错误
- 未捕获的语法错误:意外的标记ILLEGAL
- 加载xml对象时出现意外的标记ILLEGAL
- 未捕获的SyntaxError:php json_encode上出现意外的令牌ILLEGAL
- 未捕获的语法错误:将字符串传递给函数时出现意外的标记ILLEGAL
- 未捕获的语法错误:jQuery中出现意外的标记ILLEGAL