Android XML Parsing Failed Unexpected Token

In my application (game) I need to read an XML script and include it in the class object; I completed the whole XML reader through the DOM

but when I started, I got the following error:

05-08 23:03:22.342: I/System.out(588): XML Pasing Excpetion = org.xml.sax.SAXParseException: Unexpected token (position:TEXT                     ...@1:69 in java.io.InputStreamReader@4129a200) 

I read some answers about this, but they all failed to fix my problem (http://stackoverflow.com/questions/7885962/android-utf-8-file-parsing) ..

here is my code:

    InputStream inputStream = ctx.getResources().openRawResource(R.xml.script);
ctx.getApplicationContext().getPackageName()+"/xml/"+path);



        Reader reader = new InputStreamReader(inputStream,"UTF-8");

        InputSource is = new InputSource(reader);
        is.setEncoding("UTF-8");


        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();


        Document root = db.parse(is);

depending on the problem, I also tried this:

 InputStream inputStream = ctx.getResources().openRawResource(R.xml.script);
 Document root = db.parse(inputStream);

which threw exactly the same exceptions ...

How to solve this problem?

my xml file:

<script>

<scene no="0">
    <character id="1">1</character>

    <dialog no="1">
        <title>1</title>
 Sub-Element 1
    </dialog>
</scene>



</script>
+3
source share
2 answers

XML . " 1" . XML- , XML: <?xml version="1.0" ?> , :

<?xml version="1.0" ?>
<script>
<scene no="0">
    <character id="1">1</character>
    <dialog no="1">
        <title>1</title>
        <something_else>Sub-Element 1</something_else>
    </dialog>
</scene>
</script>

"Sub-Element" ( something_else) 1 .

+6

XML ? "res". "". Res-solution - "res" apk. "", , . InputSource

getAssets().open("yourfilename.xml")
+3

All Articles