asp输出xml格式文件时的一个诡异错误及解决方法:XML declaration allowed only at the start of the document
来源:互联网 发布:广州数控车床编程实例 编辑:程序博客网 时间:2024/05/17 03:00
今天要做asp根据输入参数来判断输出文本的格式,做到输出xml时发生了一个很诡异的错误,但是输出的数据又是正确的,看着不爽,相关资料也查不到,自己想办法解决了。
先来看看这个很诡异的错误:
代码片段如下:
<%@ CODEPAGE=936 %><% Option Explicit %><% Response.Charset="gb2312" %><!--#include file="getdata.asp"--><%loadtype=Request("t")select case loadtypecase ""case "json"case "xml"%><% response.contentType="text/xml" %><?xml version='1.0' encoding='gb2312'?><a> <b> <c><%= site(1,1)%></c> <d><%=Plutname(2)%></d> <e><%=Plut(2,1)%></e> </b></a><%case "m"if errmsg="" thenelseResponse.write "<span>" & errmsg & "</span>"end if%></body> </html><%case "w"%><!DOCTYPE html><html><head></head> <BODY>此处略</body> </html><%end select%>以上错误出现在
<?xml version='1.0' encoding='gb2312'?>
这里。一开始以为是
<% response.contentType="text/xml" %>
需要放在第一行,试了,无用,依旧报错。后来将
<?xml version='1.0' encoding='gb2312'?>
放到第一行问题解决。但是这不符合我的要求。于是试了将
<?xml version='1.0' encoding='gb2312'?>
改为用代码输出,居然就可以了。
可见,估计是输出xml时检测整个文本,因为还有好多语句跟着前后,故报错。而改为直接输出后,浏览器得到的就只是单一的xml文本数据再进行格式判断,这样就正常了。
case "xml"%><% response.contentType="text/xml" %><% Response.write "<?xml version='1.0' encoding='gb2312'?>" %><a> <b> <c><%= site(1,1)%></c> <d><%=Plutname(2)%></d> <e><%=Plut(2,1)%></e> </b></a><%
以上部分将原本的直接写xml头信息改为输出:
<% Response.write "<?xml version='1.0' encoding='gb2312'?>" %>这样就正常了。
附上asp的 response.contentType 备查:
‘-------以下内容摘录自知道
ajax开发中在请求服务器端的响应时, 对于每一种返回类型 规范的做法是要在服务端指定response的contentType
常遇到下面的几种情况:
1、 服务端需要返回一段普通文本给客户端,Content-Type="text/plain"
2 、服务端需要返回一段HTML代码给客户端 ,Content-Type="text/html"
3 、服务端需要返回一段XML代码给客户端 ,Content-Type="text/xml"
4 、服务端需要返回一段javascript代码给客户端
5 、服务端需要返回一段json串给客户端
我们主要讨论返回javascript代码和Json对象的情况。
javascript 的 contentType 按最标准的写法 应该是 application/javascript。而常用的
text/javascript 已经被 rfc定义为废弃的。
但是 在这里暂时不建议使用 application/javascript . 大家还是继续使用 text/javascript
为好. 因为很多老旧浏览器并不支持 application/javascript .
而所有浏览器都支持text/javascript. 在标准和广泛的兼容性之间 还是暂且选择后者吧。
json 的 contentType 常见写法有 : text/json &
text/javascript .
但是 这个 text/json 其实是根本不存在的, 而 text/javascript 在有些时候客户端处理起来会有歧义.
对于json的contentType , rfc里定义的标准写法是 :application/json.
在这里毫无疑问 我们应该选择标准写法的 application/Json。
常遇到下面的几种情况:
1、 服务端需要返回一段普通文本给客户端,Content-Type="text/plain"
2 、服务端需要返回一段HTML代码给客户端 ,Content-Type="text/html"
3 、服务端需要返回一段XML代码给客户端 ,Content-Type="text/xml"
4 、服务端需要返回一段javascript代码给客户端
5 、服务端需要返回一段json串给客户端
我们主要讨论返回javascript代码和Json对象的情况。
javascript 的 contentType 按最标准的写法 应该是 application/javascript。而常用的
text/javascript 已经被 rfc定义为废弃的。
但是 在这里暂时不建议使用 application/javascript . 大家还是继续使用 text/javascript
为好. 因为很多老旧浏览器并不支持 application/javascript .
而所有浏览器都支持text/javascript. 在标准和广泛的兼容性之间 还是暂且选择后者吧。
json 的 contentType 常见写法有 : text/json &
text/javascript .
但是 这个 text/json 其实是根本不存在的, 而 text/javascript 在有些时候客户端处理起来会有歧义.
对于json的contentType , rfc里定义的标准写法是 :application/json.
在这里毫无疑问 我们应该选择标准写法的 application/Json。
’-------------------
阅读全文
0 0
- asp输出xml格式文件时的一个诡异错误及解决方法:XML declaration allowed only at the start of the document
- php 输出xml错误不能解析,XML declaration allowed only at the start of the document
- XML declaration allowed only at the start of the document 问题解决方法
- simplexml_load_string报错:XML declaration allowed only at the start of the document
- 【XML码农】【Error】The XML declaration may only appear at the very beginning of the document.
- XML文件要有根标签(Extra content at the end of the document in file 错误
- XML文件要有根标签(Extra content at the end of the document in file 错误)
- XML or text declaration not at start of entity
- XML or text declaration not at start of entity异常的原因
- delphi 7 调用web services时报 Invalid at the top level of the document错误的解决方法
- 由于空格引起的xml错误之The processing instruction target matching "[xX][mM][lL]" is not allowed以及the markup in the document prec
- Unexpected XML declaration. The XML declaration must be the first node in the document and no white
- Error:(6) Error parsing XML: XML or text declaration not at start of entity
- Could not compile the mapping document: *******.hbm.xml 的解决方法
- mybatis 配置错误 XML document structures must start and end within the same entity
- Android编译出现XML or text declaration not at start of entity
- spring的配置文件applicationContext.xml异常Cannot find the declaration of element 'beans'.
- XML文件警告:No grammar constraints (DTD or XML schema) detected for the document.的解决方法!
- 顺序表应用--学生信息管理系统
- 国企下岗潮时期的共享经济,工人们的另一个庇护
- Faraday Future自动驾驶团队核心成员曝光
- 清空委托链
- 使用backtrace获取堆栈信息
- asp输出xml格式文件时的一个诡异错误及解决方法:XML declaration allowed only at the start of the document
- Python发送电子邮件.
- 实际中前后端开发数据交互是怎么样的
- Elon Musk公布特斯拉“下半场”目标:打造一个新能源公司 | 新智驾Weekly
- 乐视超级汽车智驾副总裁倪凯:为何被誉为“中国无人驾驶第一人”
- 浅谈C++中的重载、覆盖、隐藏
- leetcode5:最长回文子串
- 通过HTTP请求响应过程了解HTTP协议
- 支持向量机SVM(一)