search
HomeBackend DevelopmentPHP TutorialInvalid byte 1 of 1-byte UTF-8 sequence solution_PHP tutorial
Invalid byte 1 of 1-byte UTF-8 sequence solution_PHP tutorialJul 13, 2016 am 10:43 AM
byteinvalidphputf-8xmluseMethodexisthoursolveparse

When using PHP to parse xml, it prompts that Invalid byte 1 of 1-byte UTF-8 sequence is wrong. Baidu checked this problem and said it was an encoding problem. As a result, I processed the encoding and it turned out to be KO. I will share the solution below. way.

Error message

Invalid byte 1 of 1-byte UTF-8 sequence

Cause Analysis

The default encoding of java under the Chinese version of window is GBK, that is, although we have marked that the xml should be saved in utf-8 format, the file is actually saved in GBK format, so this is why The reason why we can use GBK and GB2312 encoding to generate xml files can be parsed correctly, but the files generated in UTF-8 format 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

The problem can be solved by parsing and trim() the string first.

Solution:

1. The easiest way is to change to

2. Or when opening the xml and saving it as a file, change the character set to UTF-8 and save it

Or change the program

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"); //改变编码方式 
XMLWriter writer = new XMLWriter(new FileWriter "d:dom4j.xml"), of); 

Copy code


SAXReader reader = new SAXReader();

org.dom4j.Document document = reader.read("D:ha.xml"); OutputFormat of = new OutputFormat(); of.setEncoding("UTF-8"); //Change encoding method

XMLWriter writer = new XMLWriter(new FileWriter "d:dom4j.xml"), of);

I am using the eclipse editor and just do the following can be changed in Eclipse, in the eclipse menu [Project] → [Properties], [Resources], on the right "Text file encoding", change the original to y?? , change it to "UTF-8". http://www.bkjia.com/PHPjc/633192.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/633192.htmlTechArticleWhen using php to parse xml, it prompts Invalid byte 1 of 1-byte UTF-8 sequence. This problem is wrong. Baidu checked and said it was an encoding problem. As a result, I processed the encoding and it turned out to be KO. Here I go...
Statement
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
golang 报错:“undeclared name…” 如何解决?golang 报错:“undeclared name…” 如何解决?Jun 24, 2023 pm 03:31 PM

Golang(Go编程语言)是一种基于C语言的编程语言,被广泛用于Web开发、网络编程、操作系统等领域。然而,在编写Golang程序时经常会遇到一个常见的问题,就是“undeclaredname”(未声明名称)错误。下面将介绍如何解决这个问题。了解错误信息在编译和运行Golang程序时,如果遇到了未声明名称错误,会在控制台输出相应的错误信

Java中的ClassNotFoundException——找不到类要怎么解决?Java中的ClassNotFoundException——找不到类要怎么解决?Jun 25, 2023 am 08:30 AM

Java中的ClassNotFoundException是一种常见的编译错误。当我们尝试使用Java虚拟机(JVM)加载某个类时,如果JVM找不到该类,就会抛出ClassNotFoundException。这个错误可能出现在程序运行时,也可能出现在编译时。在本文中,我们将讨论什么是ClassNotFoundException,它为什么会发生以及如何解决它。C

golang 编译错误:"undefined: json.Marshal" 如何解决?golang 编译错误:"undefined: json.Marshal" 如何解决?Jun 24, 2023 pm 03:24 PM

Go语言是一门越来越受欢迎的编程语言,它的简洁、高效、易于编写的特点已经被越来越多的开发者所认可。而在Go语言开发中,遇到编译错误是不可避免的。其中一个常见的错误就是“undefined:json.Marshal”。这个错误通常发生在你使用了Go标准库的“encoding/json”包时,编译器提示找不到“json.Marshal”的定义。这个问题的根本原

Java错误:JDBC错误,如何解决和避免Java错误:JDBC错误,如何解决和避免Jun 24, 2023 pm 02:40 PM

随着Java的广泛应用,Java程序在连接数据库时经常会出现JDBC错误。JDBC(JavaDatabaseConnectivity)是Java中用于连接数据库的编程接口,因此,JDBC错误是在Java程序与数据库交互时遇到的一种错误。下面将介绍一些最常见的JDBC错误及如何解决和避免它们。ClassNotFoundException这是最常见的JDBC

Golang函数的byte、rune和string类型转换技巧Golang函数的byte、rune和string类型转换技巧May 17, 2023 am 08:21 AM

在Golang编程中,byte、rune和string类型是非常基础、常见的数据类型。它们在处理字符串、文件流等数据操作时发挥着重要作用。而在进行这些数据操作时,我们通常需要对它们进行相互的转换,这就需要掌握一些转换技巧。本文将介绍Golang函数的byte、rune和string类型转换技巧,旨在帮助读者更好地理解这些数据类型,并能够熟练地在编程实践中应用

golang 报错:“undefined variable or function” 如何解决?golang 报错:“undefined variable or function” 如何解决?Jun 24, 2023 pm 05:18 PM

Go语言作为一门快速发展的编程语言,被广泛应用于各种项目和领域。然而,在使用golang编写程序时,你有可能会遇到一些报错,其中一个常见的报错是“undefinedvariableorfunction”。那么,这个错误是什么意思?它是如何产生的?又该如何解决呢?本文将会对这些问题进行探讨。首先,我们需要了解一些基本概念。在golang中,变量和函数是两

golang 报错:“invalid use of , operator” 如何解决?golang 报错:“invalid use of , operator” 如何解决?Jun 24, 2023 pm 07:15 PM

近年来,Golang一直受到越来越多开发者的青睐。但是,即使是最有经验的开发人员也会遇到一些挫折,比如一些报错。其中,一种常见的报错是:“invaliduseof,operator”。在这篇文章中,我将为大家介绍这个报错的原因,以及解决方法。首先,我们需要了解什么是","操作符。在Golang中,","操作符通常被用来在数组、参数列表或结构体中分隔不

1byte等于多少bit1byte等于多少bitMar 19, 2021 pm 02:52 PM

1byte等于8bit。数据存储是以“字节”(Byte)为单位,数据传输大多是以“位”(bit)为单位,一个位就代表一个0或1(即二进制),每8个位(bit)组成一个字节(Byte),是最小一级的信息单位;因而,“1Byte=8bit”。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft