Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Error reading XML file

+10 votes

We're trying to read values from an XML file. Right now, we're testing with a local XML file saved in the project folder. Every time we try to run the program, we get the following error:

Execution failed for task 'app:mergeDebugResources'.
> Unsupported type 'resource' in file H:\AndroidStudios\GradliciousVikingHub\app\src\main\res\values\temp.xml

When I open the XML file we're using for testing, I don't get any signs of errors, and everything looks correct. Here's what the XML looks like:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <resource>
        <productname>Jeans</productname>
        <productcolor>red</productcolor>
        <productquantity>5</productquantity>
    </resource>
    <resource>
        <productname>Tshirt</productname>
        <productcolor>blue</productcolor>
        <productquantity>3</productquantity>
    </resource>
    <resource>
        <productname>shorts</productname>
        <productcolor>green</productcolor>
        <productquantity>4</productquantity>
    </resource>
</resources>

Any ideas about what might be going wrong?

asked Apr 24, 2015 in Spring 2015 by Andrew Shearouse (100 points)
The XML looks fine to me, can you post the code where you try and open the XML?

2 Answers

+4 votes
 
Best answer
I believe that XML files you place in the "values" folder, it must follow strict Android-specific XML schemas.  You can't just do free-form xml there.

Instead, you probably want to put your custom XML file into the "raw" resources folder, and load it up from there, inside your app.
answered Apr 25, 2015 by Forrest Stonedahl (3,308 points)
selected May 18, 2015 by Andrew Shearouse
Thanks! I'll give that a try...if it works, then it may take care of the problem we were running into with trying to download a file from the network on the main thread.
0 votes
I believe this is due to the way Android Studio compiles the xml in your app. Try saving and accessing the file outside of your project root.
answered Apr 24, 2015 by Ethan Wojcinski (100 points)
...