我不知道如何在 Android 中为资源获取正确的 XML 结构。
我已经将 recepies.xml 保存到 values 文件夹中,并想解析它们。
<?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>
但是,我得到或“无效的开始标记”,
如果我在没有像这样的 recipies 标签的情况下格式化它:
<?xml version="1.0" encoding="UTF-8" standalone="yes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?>
我明白了,不再允许使用伪属性。
如果我只使用这个:
<?xml version="1.0" encoding="UTF-8"?>
我知道标记格式不正确。
我想我缺少一些 XML 格式设置的基础知识,但我不知道是什么。
最佳答案
/res/values
文件夹仅用于 android 资源。您只能在此处定义其中一种类型的资源。
http://developer.android.com/guide/topics/resources/available-resources.html
如果您想要自己的 xml 文件,请将其放在 /assets
文件夹中。
关于android - Android XML 资源文件的正确结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12799967/