有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java组织。阿帕奇。融洽xml。$ParseException:第1行第0列:格式不正确

首先,我为我的英语感到抱歉,我不是以英语为母语的人

我有一个安卓应用程序,我试图解析手机上任何地方的xml文件(通过文件选择器选择)。我从文件选择器中得到如下路径:/storage/emulated/0/file。xml

这是xml文件:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<kartenset>
<row thema="Test"><id>22</id><id_thema>14</id_thema><frage>Frage 1</frage><frage_bild/><antwort_text>Frage 1 Antowrt</antwort_text><antwort_bild/></row>
<row thema="Testfdd"><id>23</id><id_thema>14</id_thema><frage>Frage 2</frage><frage_bild/><antwort_text>Frage 2 Antwort</antwort_text><antwort_bild/></row>
</kartenset>

我觉得这部分也很有趣

 InputSource inputSource = new InputSource();
 inputSource.setEncoding("utf-8");
 inputSource.setCharacterStream(new StringReader(path));
 xr.parse(inputSource);

当我从web下载同一个文件时,xml解析器正在工作(当然是url openstream…)

我也试过:

xr.parse(new InputSource(cont.getResources().getAssets().open(p_uri)));

还有不同的编码

我希望任何人都能帮助我。谢谢

编辑:

我明白了。现在它起作用了。也不例外。解决方案是:

InputSource inputSource = new InputSource();
inputSource.setEncoding("utf-8");
inputSource.setCharacterStream(new StringReader(p_uri));

xr.parse(new InputSource(new FileReader(new File(p_uri))));

共 (0) 个答案