Android - 使用解析的xml数据来更新SQLite

时间:2012-07-10 10:16:15

标签: android multidimensional-array xml-parsing

只是提醒我,我是一个菜鸟,所以也许我的问题相当愚蠢...

无论如何,我正在使用SAX来解析XML文件,我可以正确地遍历项目并将其内容打印到日志中。我需要的是这个解析器返回一个多维关联数组,我可以迭代并随后用来更新SQLite数据库......

问题(S): Android中是否存在这样的事情?我应该使用其他一些数据类型吗?怎么做?

我将包含一些解析器的代码(endElement方法执行打印记录,到目前为止,每个项目只有一个元素,但是会改变,因此需要多维):

private boolean in_image = false;
private boolean in_homeimage = false;
StringBuilder sb;

@Override
public void characters(char[] ch, int start, int length)
        throws SAXException {

        for (int i=start; i<start+length; i++) {
            sb.append(ch[i]);
        }

    //super.characters(ch, start, length);
}

@Override
public void endElement(String uri, String localName, String qName)
        throws SAXException {
    if( localName.equals("image") && this.in_homeimage ){
        this.in_homeimage = false;
        Log.i("Extra", "Found homeimage: " + sb);
    }
    else if( localName.equals("image") ){
        this.in_image = false;
        Log.i("Extra", "Found image: " + sb);
    }

    //super.endElement(uri, localName, qName);
}

@Override
public void startElement(String uri, String localName, String qName,
        Attributes attributes) throws SAXException {

    sb = new StringBuilder();

    if( localName.equals("image") && attributes.getValue("name") == "home" )
        this.in_homeimage = true;
    else if( localName.equals("image") )
        this.in_image = true;

    //super.startElement(uri, localName, qName, attributes);
}

提前致谢

0 个答案:

没有答案