The error contents are:
Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
The online summary is the analysis content contains BOM 。 This tag is invisible. There is only this tag in the stream.
BOM: byte order mark, Chinese name, byte order mark. The UCS specification recommends that the BOM be transmitted before the byte stream is transmitted to judge the byte order.
in fact, UTF-8 does not need BOM to indicate the byte order, but BOM can be used to indicate the encoding method. The UTF-8 code of BOM is EF BB BF. Therefore, if the receiver receives the byte stream beginning with EF BB BF, it indicates that it is UTF-8 code
solution:
if you are parsing a file :
You can use UltraEdit or emeditor to open XML and save it as. When saving, you can choose whether to save it in UTF-8 without BOM or UTF-8 with BOM
if the content is returned from a remote request:
If you change the returned stream new to a string, you will not see the BOM, but you must intercept the content you need:
if(null != result && !"".equals(result)){ if(result.indexOf("<") != -1 && result.lastIndexOf(">") != -1 && result.lastIndexOf(">") > result.indexOf("<")) result = result.substring(result.indexOf("<"), result.lastIndexOf(">") + 1); }
It is also said that it is caused by the lower version of Dom4j, but I have seen that the version I use is 1.6.1, so this possibility is excluded, but in practice, I still recommend using the latest stable version for development
Similar Posts:
- The difference between UTF-8 and utf-8-sig
- org.xml.sax.SAXParseException: Content is not allowed in trailing section
- [Solved] Typeerror: can read property ‘index of’ of null
- Resource interpreted as Stylesheet but transferred with MIME type text/html: css not work
- java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
- How to Solve Error: Server returned HTTP response code: 403 for URL:
- Solve the problem of “resource interpreted as document but transferred with MIME type application / JSON” in IE browser
- Chrome failed to download word
- [Solved] Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
- System.Xml.XmlException: There is no Unicode byte order mark. Cannot switch to Unicode.