Android XML parse failed Unexpected token

前端 未结 2 380
盖世英雄少女心
盖世英雄少女心 2021-01-21 00:33

In my app(game), i need to read a XML script and turn in into a class object; i\'ve completed the entire XML reader via DOM

but when i run , i got the following error:<

相关标签:
2条回答
  • 2021-01-21 01:09

    Your XML is invalid. "Sub-Element 1" should be within an element itself. XML-documents should also begin with a tag defining it as XML: <?xml version="1.0" ?> So your complete file would be:

    <?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>
    

    Or you could use "Sub-Element" as the element name (instead of something_else) and 1 as the value.

    0 讨论(0)
  • 2021-01-21 01:13

    Where do you store your xml file? In "res" folder. You should store it in "assets". Res-solution is not working because of specific of the "res" folder and it's presentation in the apk. Move your file to the "assets" and you'll see that everything is working. Use the following code for creating InputSource

    getAssets().open("yourfilename.xml")
    
    0 讨论(0)
提交回复
热议问题