Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在java中解析xml时遇到了一些问题。在文本中找到的引用在不同的浏览器文本编码中是这样的:
iso-8859-1 | utf-8 (“ | “ †| ” ’ | ’
我试图在 xml 字符串中解析两者以显示在我的 android 应用程序中。但是,这两个符号都无法成功解析。
在解析文本之前,我被迫替换“to”和“to”(并在 php 中对它们进行编码)。
我可以知道为什么吗?XML 解析器不允许任何特殊符号?
大多数 XML 解析器应该使您能够指定输入的编码。如果您使用的是 XMLPullParser,您可以像这样更改它:
parser.setInput(this.getInputStream(),"UTF-8");
如果您将 SAX 与 InputStream 一起使用,请更改 InputStream 的编码,如下所示:
is.setEncoding("UTF-8");