[英]Is encoding Cp1252 invalid in an XML file?
Some XML file I ran across is failing a well-formed XML check, even though it looks well-formed to me (I might be wrong.) 我遇到的一些XML文件未能通过格式良好的XML检查,即使它看起来很好(我可能错了。)
I have reduced it to a trivial example: 我把它简化为一个简单的例子:
<?xml version="1.0" encoding="Cp1252"?>
<jnlp/>
The method being used to do the check works like this: 用于执行检查的方法如下所示:
public static boolean isWellFormedXml(InputStream inputStream) {
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_COALESCING, false);
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader reader = inputFactory.createXMLStreamReader(stream);
try {
// Scan through all the reader tokens to ensure everything is well formed
while (reader.hasNext()) {
reader.next();
}
} finally {
reader.close();
}
} catch (XMLStreamException e) {
// Ignore the exception
return false;
}
return true;
}
The error I'm seeing is: 我看到的错误是:
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,40]
Message: Invalid encoding name "Cp1252". 消息:无效的编码名称“Cp1252”。
Only problem is - I can breakpoint at the catch and confirm that this encoding name does resolve. 唯一的问题是 - 我可以在catch上断点并确认此编码名称确实解决了。 So what's the deal here? 那么这里的交易是什么? Does XML also restrict which encodings you're allowed to use in the prologue? XML是否也限制允许在序言中使用哪些编码?
check: 校验:
http://www.iana.org/assignments/character-sets/character-sets.xml http://www.iana.org/assignments/character-sets/character-sets.xml
i guess the encoding you're looking for COULD be windows-1252. 我想你正在寻找的编码可能是windows-1252。 Cp1252 might be a valid charset in java, but in XML, you're not supposed to use it (by that name). Cp1252可能是java中的有效字符集,但在XML中,您不应该使用它(通过该名称)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.