PHP parsing xml prompts Invalid byte 1 of 1-byte UTF-8 sequence error processing method_PHP tutorial

WBOY
Release: 2016-07-13 10:25:12
Original
872 people have browsed it

Error message
Invalid byte 1 of 1-byte UTF-8 sequence
Cause analysis
In the Chinese version of the window, the default encoding of java is GBK, that is, although we have marked the xml is saved in utf-8 format but in fact the file is saved in GBK format, so this is why we can use GBK and GB2312 encoding to generate xml files that can be parsed correctly, while files generated in UTF-8 format The reason why it cannot be parsed by the xml parser.

Change the encoding attribute value of xml from UTF-8 to UTF8
org.xml.sax.SAXParseException: Content is not allowed in trailing section
It can be solved by parsing and trim() the string first question.
Solution:
1. The simplest is to change to
2. Or change the character set to UTF-8 when opening the xml and save it
or change the program

Copy code The code is as follows:

SAXReader reader = new SAXReader();
org.dom4j.Document document = reader.read("D:ha.xml");
OutputFormat of = new OutputFormat();
of.setEncoding("UTF-8"); //Change the encoding method
XMLWriter writer = new XMLWriter(new FileWriter "d:dom4j.xml"), of);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825159.htmlTechArticleError prompt Invalid byte 1 of 1-byte UTF-8 sequence Cause analysis The default of java under the Chinese version of window The encoding is GBK, that is, although we have identified that the xml should be saved in utf-8 format...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!