【问题标题】:Malformed XML fragment: a name was started with an invalid character 'ñ'格式错误的 XML 片段:名称以无效字符“ñ”开头
【发布时间】:2014-03-31 16:59:58
【问题描述】:

对不起,我的英语不好。 我是 Progress 4GL 开发人员。 当我执行 RUN 语句以执行 Web 服务的方法时,我收到以下错误 Malformed XML fragment: a name was started with an invalid character 'ñ'

XML 结构是这样的:

<RecuperarDatosGeneralesVehiculoXCodigoInfoAuto 
    xmlns:ns0="http://www.example.com.ar/">
    <ns0:lsCodInfoAuto>12410</ns0:lsCodInfoAuto>
    <ns0:añoModelo>2012</ns0:añoModelo>
</RecuperarDatosGeneralesVehiculoXCodigoInfoAuto>

此结构无法修改,因为它是由 Web 服务的开发人员设计的。

谁能帮帮我?

【问题讨论】:

  • 你的XML返回值有处理说明吗?像&lt;?xml version='1.0' encoding='ISO-8859-1'?&gt; 之类的吗?
  • 见stackoverflow.com/questions/2873228/…。这样做似乎是合法,所以首先要检查的是 ñ 字符是否以正确的编码编写,以便与此应用程序一起使用。使用非 ASCII 字母是否是个好主意存在争议。
  • 鲁本斯,是的,我有,但仍然出现错误
  • 是的,您需要确保正确指定了编码。
  • 对不起,我没有说明编程语言已经是Progress 4GL,并尝试通过相应的编码。但我仍然得到同样的错误。

标签: xml web-services progress-4gl


【解决方案1】:

我仍然认为这与文件的代码页/字符集有关。我尝试将您的 xml 复制粘贴到文档中,添加 xml-start 标记并在 Progress 会话中读取它,并得到与您类似的错误。在不同的浏览器中打开相同的文件也会产生错误。

但是,下面的示例生成带有 ñ 标记的 xml,并且不仅可以在 Progress 中打开(该示例正是这样做的),还可以在不同的浏览器中打开。

我还将 xml 读入正在进行的一般 xml 文档并保存它的副本 - 标记中仍然带有 ñ 字符。

虽然 xml 不像您的那样 100% 形成,但它仍然是一个可以帮助您的示例。

/* 
Defining a temp-table named ttRecuperarDatos.
Note: 
1) I have to put the long name (RecuperarDatosGeneralesVehiculoXCodigoInfoAuto) 
as SERIALIZE-NAME (could use XML-NODE-NAME as well) since Progress only allows for 
32 character long names 

2) añoModelo needs to be put AS SERIALIZE-NAME as well since
Progress wont let me use special character as field names. 

*/

DEFINE TEMP-TABLE ttRecuperarDatos NO-UNDO SERIALIZE-NAME "RecuperarDatosGeneralesVehiculoXCodigoInfoAuto"
    FIELD lsCodInfoAuto AS CHARACTER 
    FIELD anoModelo     AS CHARACTER SERIALIZE-NAME "añoModelo".

/* Defining a copy of the first temp-table */
DEFINE TEMP-TABLE ttCopy SERIALIZE-NAME "RecuperarDatosGeneralesVehiculoXCodigoInfoAuto" LIKE ttRecuperarDatos .

/* Define a handle to a general xml-document */
DEFINE VARIABLE hXml AS HANDLE      NO-UNDO.


/* Create two records */
CREATE ttRecuperarDatos.
ASSIGN 
    ttRecuperarDatos.lsCodInfoAuto = "abc123"
    ttRecuperarDatos.anoModelo     = "1998".

CREATE ttRecuperarDatos.
ASSIGN 
    ttRecuperarDatos.lsCodInfoAuto = "cde444"
    ttRecuperarDatos.anoModelo     = "2004".

/* Write content to file */
TEMP-TABLE ttRecuperarDatos:WRITE-XML("FILE","c:\temp\testfile.xml").

/* Read content from file into second temp-table */
TEMP-TABLE ttCopy:READ-XML( "FILE"
                          , "c:\temp\testfile.xml"
                          , "EMPTY"
                          , ""
                          , FALSE).

/* Display records just to prove the READ-XML worked */
FOR EACH ttCopy:
    DISPLAY ttCopy.
END.


/* Create a new xml document */
CREATE X-DOCUMENT hXml.

/* Load content into it */
hXml:LOAD("FILE","c:\temp\testfile.xml", FALSE).

/* Save a copy to disc */
hXml:SAVE("FILE","c:\temp\testfile_copy.xml").

/* Cleanup */
DELETE OBJECT hXml.

【讨论】:

    猜你喜欢
    • 2015-06-19
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    相关资源
    最近更新 更多