【问题标题】:Grails Error: invalid XML character (Unicode: 0x5c)Grails 错误:无效的 XML 字符(Unicode:0x5c)
【发布时间】:2012-07-27 13:11:20
【问题描述】:

我对这个问题做了一些研究,但似乎所有其他答案都包括更改响应发送给您的方式。我正在调用以 xml 字符串返回的第三方 Web 服务。当我在本地 Win7 机器上执行此操作时,效果很好。但是当我把它放到我们的服务器 Win Server 2003 上时,我得到这个错误返回:

Error 500: Executing action [vinlookup] of controller [AutoVehicleController] caused   exception: null
Servlet: grails
URI: /NonProfits/grails/autoVehicle/vinlookup.dispatch
Exception Message: An invalid XML character (Unicode: 0x5c) was found in the public identifier. 
Caused by: An invalid XML character (Unicode: 0x5c) was found in the public identifier. 
Class: AutoVehicleController 
At Line: [172] 
Code Snippet:
Stack Trace
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x5c) was found in the public identifier.

    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)

    at VinPowerService.decodeVin(VinPowerService.groovy:40)

    at VinPowerService$$FastClassByCGLIB$$6f8d198b.invoke(<generated>)

    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

    at VinPowerService$$EnhancerByCGLIB$$f1db38bd.decodeVin(<generated>)

    at VinPowerService$decodeVin.call(Unknown Source)

    at AutoVehicleController$_closure7.doCall(AutoVehicleController.groovy:172)

    at AutoVehicleController$_closure7.doCall(AutoVehicleController.groovy)

    at java.lang.Thread.run(Thread.java:619)

【问题讨论】:

  • 你没有说你是如何调用网络服务的,或者显示任何抛出这个错误的代码,或者说你正在使用哪个版本的 Grails 和相关插件......它可能有用吗?

标签: xml web-services grails groovy


【解决方案1】:

消息非常明确:

在公共中发现了一个无效的 XML 字符(Unicode:0x5c) 标识符。

“公共标识符”是出现在 DOCTYPE 声明中关键字 PUBLIC 之后的字符串。公共标识符中可以出现哪些字符是有规定的,并且不允许使用反斜杠。

你有一个选择。说服生成此标识符的人改过自新,或编写某种脚本来修复收到的错误 XML。不太可能有人关心公共标识符的值是什么,因此您可能只需删除反斜杠而不会造成任何损害。

【讨论】:

    【解决方案2】:

    0x5c 是“重击”字符\,可用于“转义序列”。因此,对于 XML 内容,它需要自行转义。应该有一个像 HTMLEncode 这样的辅助函数(这里从内存中提取),它将所有这些字符转换为它们的“转义版本”(即 & 变为 &)。

    【讨论】:

    • \ 不用于在 XML 中转义。这是一个普通的标点符号。但是,它在名称标记(例如标签名称或属性名称)中无效,它只允许某些标点符号。
    • 也许这适用? link
    【解决方案3】:

    如果您的 XML 格式良好,请确认您在第一个节点之后没有空格。服务器返回一个字符串,但是它想在前面添加空格,并且发生了错误......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-10
      • 2013-09-10
      • 2019-05-13
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 2021-03-26
      相关资源
      最近更新 更多