Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the php parsing xml prompt Invalid byte 1 of 1-byte UTF-8 sequence error

Shulou Source: shulou.com Published: 2022-06-03 07:40:54 09月11日 Update

This article mainly explains "how to solve the php parsing xml prompt Invalid byte 1 of 1-byte UTF-8 sequence error", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "how to solve php parsing xml prompt Invalid byte 1 of 1-byte UTF-8 sequence error" bar!

Error prompt

Invalid byte 1 of 1-byte UTF-8 sequence

Cause analysis

In the Chinese version of window, the default encoding of java is GBK, that is, although we identified the xml to be saved as utf-8 format, the file is actually saved in GBK format, so this 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 xml parsers.

Change the value of the encoding attribute UTF-8 of xml to UTF8

Org.xml.sax.SAXParseException: Content is not allowed in trailing section

Parsing the first and the string trim () will solve the problem.

Resolve:

1. The simplest thing is to change it to

2. Or change the character set to UTF-8 when xml is opened and saved.

Or change the procedure.

The copy 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)

Thank you for your reading, the above is "how to solve php parsing xml prompt Invalid byte 1 of 1-byte UTF-8 sequence error" content, after the study of this article, I believe you on how to solve php parsing xml prompt Invalid byte 1 of 1-byte UTF-8 sequence error this problem has a more profound experience, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: UTF-8 error hint file format coding learning that is code content reason character namely problem generation Chinese version cause analysis string character set actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Xiaomi Apple MariaDB