An invalid XML character (Unicode: 0xc) was found

后端 未结 9 2041
傲寒
傲寒 2020-12-02 12:38

Parsing an XML file using the Java DOM parser results in:

[Fatal Error] os__flag_8c.xml:103:135: An invalid XML character (Unicode: 0xc) was found in the ele         


        
9条回答
  •  囚心锁ツ
    2020-12-02 13:01

    I faced a similar issue where XML was containing control characters. After looking into the code, I found that a deprecated class,StringBufferInputStream, was used for reading string content.

    http://docs.oracle.com/javase/7/docs/api/java/io/StringBufferInputStream.html

    This class does not properly convert characters into bytes. As of JDK 1.1, the preferred way to create a stream from a string is via the StringReader class.
    

    I changed it to ByteArrayInputStream and it worked fine.

提交回复
热议问题