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?
source share