1

我不知道如何为 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>

但是,我得到或“无效的开始标签”,

如果我在没有这样的收件人标签的情况下格式化它:

<?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 格式的基础知识方面遗漏了一些东西,但我不知道是什么。

4

2 回答 2

4

/res/values文件夹仅适用于 android 资源。您只能在此处定义这些类型的资源之一。 http://developer.android.com/guide/topics/resources/available-resources.html

如果您想要自己的 xml 文件,请将其放在/assets文件夹中。

于 2012-10-09T12:28:44.373 回答
1

values.xml 中的资源必须如下所示

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

您可以查看有关字符串资源TypedArray的文档以获取更多信息。

于 2012-10-09T12:28:26.190 回答