简体   繁体   中英

Proper Structure for Android XML resource file

I can't figure out how to get proper XML Structure for resources in Android.

I've saved recepies.xml into values folder, and would like to pars them.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recepies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<recepie name="recepie1">
    <item></item>
    <NumberOfPersons>1</NumberOfPersons>
    <Ingredients>
        <string></string>
        <string></string>
    </Ingredients>
    <Preparation></Preparation>
    <Energy>342</Energy>
    <Protein>8</Protein>
    <RecipeCategory>3</RecipeCategory>
</recepie>

But, I get or "Invalid start tag",

if I format it without recipies tag like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?>

I get, no more pseudo attributes allowed.

If I use only this:

<?xml version="1.0" encoding="UTF-8"?>

I get that markup is not well formed.

I guess I'm missing something in basics of XML formatting, but I can't figure out what.

/res/values folder is only for android resources. You can only define one of these type of resources here. http://developer.android.com/guide/topics/resources/available-resources.html

If you want your own xml file, place it in /assets folder.

Your resources in values.xml must look like this

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string
        name="string_name">text_string</string>
</resources>

You can check the documentation on string resources or on TypedArray to get more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM