Error tips
Invalid byte 1 of 1-byte UTF-8 sequence
Cause analysis
In the Chinese version of Windows, the default encoding of Java is GBK, which means that although we identify the XML to be saved as Utf-8 format but actually the file is saved in GBK format, so that's why we can use GBK, GB2312 encoding to generate XML files can be parsed correctly, and files generated in UTF-8 format cannot be parsed by the XML parser.
Change the encoding attribute value of the XML UTF-8 to UTF8
Org.xml.sax.SAXParseException:Content is isn't allowed in trailing
You can solve the problem by first parsing and string trim ().
Solve:
1, the simplest is to <?xml version= "1.0" encoding= "UTF-8"?> to <?xml version= "1.0" encoding= "GBK"?>
2, or the XML open to save when the character set changed to UTF-8 after saving
or change the procedure
Copy Code code 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 mode
XMLWriter writer = new XMLWriter (new FileWriter "D:\dom4j.xml"), of);