+ -
当前位置:首页 → 问答吧 → 用ASP从数据库中读出的数据生成XML,但是数据库中有特殊字符时,报错,该如何处理

用ASP从数据库中读出的数据生成XML,但是数据库中有特殊字符时,报错,该如何处理

时间:2003-05-19

来源:互联网

用ASP从数据库中读出的数据生成XML,但是数据库中有特殊字符时,报错,该如何处理,错误信息如下:

A semi colon character was expected. Error processing resource 'http://myweb.com/xmlweb/cert-rpt-XML.asp'. Line 19, Position 9

<des>K&S 1484/1488 W/B</des>
--------^

其中K&S 1484/1488 W/B为数据库中Table 里的信息.由于含有字符"&",在运行
'http://myweb.com/xmlweb/cert-rpt-XML.asp'时报以上错误.由于我不能修改
数据库table里的内容,请问如何修改我的程序.

<%@ language="VBScript" %>
<?xml version="1.0" encoding="gb2312"?>
<?xml:stylesheet type="text/xsl" href="'http://myweb.com/xmlweb/XSL/CERT-RPT-XML.xsl"?>



<% Dim Dataconn,ConStr,Connect,ADDNEWRS,ADDNEWRS2,I,Link,LINEC,C %>
<% DataConn = "d:\database\OJTDB"%>
<% Set Connect = Server.CreateObject("ADODB.Connection")%>
<% ConStr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & DataConn & ";" %>
<% Connect.open(ConStr) %>
<% Set ADDNEWRS=Server.CreateObject("ADODB.Recordset") %>

<% ADDNEWRS.Open "SELECT * FROM [CERT-WillExpire] ORDER BY [CERT-WillExpire].[DEPT NO],[CERT-WillExpire].[certification DATE]",Connect, 1,3 %>

<certdata>


<% ADDNEWRS.MOVEFIRST %>
<% I=0 %>
<% DO until ADDNEWRS.EOF %>
<% I=I+1 %>

<certrecord>
<SN><% =I %></SN>
<deptno><% =ADDNEWRS("DEPT NO") %></deptno>
<name><% =ADDNEWRS("name(e)") %></name>
<certcode><% =ADDNEWRS("certificate") %></certcode>
<des><% =ADDNEWRS("machine/process introduction") %></des>
<type><% =ADDNEWRS("MAIN") %></type>
<date><% =ADDNEWRS("certification Date") %></date>
</certrecord>

<% ADDNEWRS.MOVEnext %>
<% LOOP %>
</certdata>

作者: Amo_Lin   发布时间: 2003-05-19

CDATA[]

作者: 上水道的   发布时间: 2003-05-19

我用的是schema ,应该怎样做? 再次感谢!

作者: Amo_Lin   发布时间: 2003-05-19

schema 是做验证

试试
<des><![CDATA[<% =ADDNEWRS("machine/process introduction") %>]></des>
要么用脚本替换

作者: bencalie   发布时间: 2003-05-19

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

A CDATA section was not closed. Error processing resource 'http://myweb.com/xmlweb/cert-rpt-XML.asp'. Line 19, Position 15


<des><![CDATA[CAL BY USER]></des>
--------------^

作者: Amo_Lin   发布时间: 2003-05-19

Sorry,漏了一个],再试试?

<des><![CDATA[<% =ADDNEWRS("machine/process introduction") %>]]></des>

脚本就是把&替换成&amp;(半角)

作者: bencalie   发布时间: 2003-05-19

Cool,OK了,谢谢高人!!!

作者: Amo_Lin   发布时间: 2003-05-19