0

私はXmlResourceParserを使おうとしていますが、それがその仕事に適したツールだとは思いません。サブアイテムを持つアイテムのセットがあり、次のリストの2番目のアイテムなど、特定のアイテムを引き出したいと考えています。

<story>
    <id>1</id>
    <name>The First Room</name>
    <description>You aren't sure how you ended up here, but there is nothing in this room of interest. You should probably escape.</description>
    <direction>
        <name>North</name>
        <id>2</id>
    </direction>
    <direction>
        <name>East</name>
        <id>3</id>
    </direction>
</story>
<story>
    <id>2</id>
    <name>Moldy Room</name>
    <description>This room is filled with mold. It would be hazardous to your heath to stick around here.</description>
    <direction>
        <name>South</name>
        <id>1</id>
    </direction>
    <direction>
        <name>West</name>
        <id>4</id>
    </direction>
</story>

自分でオブジェクトを設定しなくても、簡単に言うと「id」番号でプルできるようにしたいと思います。もし可能なら。

4

1 に答える 1

0

このコードを使用できます:

        Resources res = activity.getResources();
        XmlResourceParser xpp = res
                .getXml(R.xml.myxml);
        xpp.next();
        int eventType = xpp.getEventType();
        eventType = xpp.next();
        eventType = xpp.next();
        eventType = xpp.next();

        short id = Short
                .parseShort(xpp.getText());

        Toast.makeText(
                activity.getApplicationContext(),
                "" + id, Toast.LENGTH_LONG)
                .show();
于 2012-05-29T17:57:39.627 に答える