When parsing xml with PHP prompt invalid byte 1 of 1-byte UTF-8 sequence error, this problem I Baidu verified that is coding problem, the result I put the code to deal with really KO, below I to share the solution.
Error hints
Invalid byte 1 of 1-byte UTF-8 sequence
Cause analysis
In the Chinese version of the window under the Java default encoding is GBK, that is, although we have identified to save XML in the Utf-8 format but actually the file is saved in GBK format, so that is why we can use GBK, GB2312 encoding to generate XML files can be parsed correctly, while files generated in UTF-8 format cannot be parsed by the XML parser.
Change the encoding attribute value of XML UTF-8 to UTF8
Org.xml.sax.SAXParseException:Content isn't allowed in trailing section
Solve the problem by first parsing and string trimming ().
Solve:
1, the simplest is to change into
2, or to open the XML when the save character set to UTF-8 after the save
or change the program
The code is as follows |
Copy Code |
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; |
I'm using the Eclipse editor to do the following
Can be changed in Eclipse, in the Eclipse's function table [Project]→[properties],?? [Resources], in the right "text file encoding", the original Xing to Y?? ??, change? "utf-8".
http://www.bkjia.com/PHPjc/633192.html www.bkjia.com true http://www.bkjia.com/PHPjc/633192.html techarticle When using PHP parsing XML prompt Invalid byte 1 of 1-byte UTF-8 sequence error, this problem I Baidu verified that is coding problem, the result I put the code to deal with really ko, below I come ...