2012-07-27 51 views
2

我對這個問題做了一點研究,但似乎所有其他答案都包括更改響應發送給您的方式。我正在調用第三方web服務,它返回一個xml字符串。當我在我的本地Win7機器上做什麼時,情況就好了。但是,當我把它拿出來給我們的服務器,運Server 2003中,我得到這個錯誤的回報:Grails錯誤:無效的XML字符(Unicode:0x5c)

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) 
+0

你不說你是如何調用webservice,或者顯示任何代碼引發這個錯誤,或者說你正在使用哪個版本的Grails和相關插件......這可能有用嗎? – 2012-07-27 15:14:59

回答

2

的信息是非常明確的:

An invalid XML character (Unicode: 0x5c) was found in the public identifier.

「公共標識符」是後出現的字符串DOCTYPE聲明中的關鍵字PUBLIC。有哪些字符可以出現在公共標識符中,並且不允許反斜槓。

您有選擇。說服產生這個標識符的人來修補他們的方式,或者寫一些腳本來修復收到的壞XML。任何人都不太可能關心公共標識符的價值,所以你可以直接刪除反斜槓而不會造成任何損害。

1

0x5c是「捶」字\,可用於「轉義序列」。因此,它需要爲XML內容自行轉義。應該有一個幫助函數,如HTMLEncode(從內存中抽取),將所有這些字符轉換爲其「轉義版本」(即&變爲&)。

+0

該'''''不用於在XML中轉義。這是一個正常的標點符號。它在名稱標記(例如標記名稱或屬​​性名稱)中無效,但只允許使用某些標點符號。 – ataylor 2012-07-27 15:49:24

+0

沒錯,我沒有澄清。 – Darek 2012-07-27 20:46:54

+0

也許這適用? [鏈接](http://stackoverflow.com/questions/5858684/getting-jdomexception-on-one-machine-but-the-same-xml-works-fine-in-another) – Darek 2012-07-27 20:48:57

0

如果您的XML格式良好,請驗證您在第一個節點之後不要有空白。服務器返回一個字符串,但它希望前加空格,而且,出現錯誤而發生......

相關問題