Is cp1252 encoding invalid in xml file?

In some XML file that I came across, a well-formed XML check does not work, although it looks well-formed for me (I may be wrong.)

I brought it to a trivial example:

<?xml version="1.0" encoding="Cp1252"?> <jnlp/> 

The method used to perform the verification is as follows:

 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 see is:

 javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,40] 

Message: Invalid encoding name "Cp1252".

Only problem is I can stop on catch and confirm that this encoding name resolves. So what's the deal? XML also limits which encodings you can use in the prolog?

+4
source share
1 answer

check:

http://www.iana.org/assignments/character-sets/character-sets.xml

I think the encoding you are looking for should be Windows-1252. Cp1252 may be a valid encoding in java, but in XML you should not use it (using this name).

+4
source

All Articles