前段时间用dom4j解析xml时碰到了个异常 content is not allowed in prolog,估计是编码问题,后来在网上找到了答案,具体看以下的代码就知道咋回事了
import java.io.*;
import java.nio.charset.Charset;
import javax.xml.parsers.*;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class ContentNotAllowedInProlog {
private static void parse(InputStream stream) throws SAXException,
ParserConfigurationException, IOException {
SAXParserFactory.newInstance().newSAXParser().parse(stream,
new DefaultHandler());
}
public static void main(String[] args) {
String[] encodings = { "UTF-8", "UTF-16", "ISO-8859-1" };
for (String actual : encodings) {
for (String declared : encodings) {
if (actual != declared) {
String xml = "<?xml version='1.0' encoding='" + declared
+ "'?><x/>";
byte[] encoded = xml.getBytes(Charset.forName(actual));
try {
parse(new ByteArrayInputStream(encoded));
System.out.println("HIDDEN ERROR! actual:" + actual + " " + xml);
} catch (Exception e) {
System.out.println(e.getMessage() + " actual:" + actual + " xml:"
+ xml);
}
}
}
}
}
}
这段代码是老外分析的,原文http://illegalargumentexception.blogspot.com/2010/09/java-content-is-not-allowed-in-prolog.html
感觉帮助颇大。
分享到:
相关推荐
设置隐试打开PPT报错 Hiding the application window is not allowed
Host 主机名 is not allowed to connect the mysql server 原因:没有授权远程访问mysql 解决方法: cmd 中运行mysql -u root -p(如果报mysql 不是内部或外部命令,找到安装mysql对应的bin文件夹运行mysql.exe,...
"Host 'localhost' is not allowed to connect to this MySQL server" 的原因及解决办法
nginx: [emerg] “proxy_cache_path” directive is not allowed here in /etc/nginx/conf.d/default.conf:29 提示意思“proxy_cache_path指令不被允许”,在官网上查找了相关说明,也没有发现问题,最后看应用范围...
mongod高级查询语句,Javascript查询和$where查询,正则表达式匹配
主要介绍了php采用curl访问域名返回405 method not allowed提示的解决方法,需要的朋友可以参考下
NULL 博文链接:https://rayoo.iteye.com/blog/1973032
jmeter源码 log4j2.xml
Android WebView 报 Not allowed to load local resource错误的解决办法 博客地址:http://blog.csdn.net/yuzhiqiang_1993/article/details/76228541
4. Note that these files are not removed when Diskeeper is uninstalled: Productname.msi (for example, Diskeeper 2008 Server.msi) DKDesktopShortcut_A4ED7F98B2A54A06855C7E8804E8460E.exe These ...
java.sql.SQLException: null, message from server: “Host ‘223.72.41.7’ is not allowed to connect to this MySQL server” 客户端访问时报错: 解决方法: 1,登陆服务器 mysql> use mysql; //用mysql ...
java.lang.UnsupportedOperationException: For security reasons, WebView is not allowed in privileged processes 因为应用是系统级别的,在AndroidManifest.xml中添加了android:sharedUserId=”android.uid....
NR5G网络拒绝码-5gmm_cause = 7 (0x7) (5GS Service not allowed)
NULL 博文链接:https://yizhilong28.iteye.com/blog/1137285
message from server: “Host ‘****’ is not allowed to connect to this MySQL server 1:在登录mysql服务器 2:执行:GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ WITH GRANT OPTION //赋予任何主机访问数据的...
opencv-2.4.9/modules/gpu/src/nvidia/core/NCVPixelOperations.hpp(51): error: a storage class is not allowed in an explicit specialization 这是由于NCVPixelOperations.hpp的问题,只要替换opencv-2.4.9/...
keil常见错误 keil常见错误 keil常见错误 keil常见错误
keil 编译时出现错误和警告总结 中国电子DIY之家
从3GPP协议和UE端行为分析5G gmm cause #27的网络问题
ERROR 1130 (HY000): Host ‘localhost’ is not allowed to connect to this MySQL server www.jb51.net 出现原因: mysql只有一个root用户,修改root密码后选了MD5,提交后,重新 登陆出现“Host ‘localhost’ is...