Java的Andr​​oid的非常大的XML解析 [英] java android very large xml parsing

查看:158
本文介绍了Java的Andr​​oid的非常大的XML解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在其中根据类别ID映射到子类别另一个XML文件一个XML文件中的类别非常大的XML文件。只类别ID和名称加载快速的XML文件,但它与图像的路径,描述,经纬度等..需要时间来加载子XML文件。

我使用javax.xml包和org.w3c.dom包。
该列表操作加载文件中的每个点击寻找子类别。
有没有什么办法让这整个过程更快?

修改-1

继承人的code我使用的参考getch子类别:
文档的DOC = this.builder.parse(插播广告,NULL);

  doc.getDocumentElement()正常化()。
        节点列表分页= doc.getElementsByTagName(页);
        最终诠释长度= pageList.getLength();        的for(int i = 0; I<长度;我+ +)
        {
            布尔inCategory = FALSE;
            元类别=(元)getChild(pageList.item(一)类别);
            如果(类!= NULL)
            {
                节点列表所属分类= categories.getElementsByTagName(类);
                对于(INT J = 0; J< categoryList.getLength(); J ++)
                {
                    如果(的Integer.parseInt(categoryList.item(J).getTextContent())== CATID)
                    {
                        inCategory = TRUE;
                        打破;
                    }
                }
            }            如果(inCategory ==真)
            {
                最终的NamedNodeMap ATTR = pageList.item(I).getAttributes();
                //                //获取页面ID
                最终诠释的categoryID =的Integer.parseInt(getNodeValue(ATTR,ID));                //获取页面名称
                最终字符串categoryName =(getChild(pageList.item(我),头衔)!= NULL)? getChild(pageList.item(我),头衔)getTextContent():无题;                //获取缩略图
                。最终的NamedNodeMap thumb_attr = getChild(pageList.item(i)中,缩略图)的getAttributes();
                最后弦乐categoryImage =placethumbs /+ getNodeValue(thumb_attr,程序文件);                //最后弦乐categoryImage =androidicon.png;                分类分类=新的类别(类别名称,的categoryID,categoryImage);                this.list.add(类);
                Log.d(标签,category.toString());
            }
        }


解决方案

也许SAX处理器会更快(假设你的应用程序正在放缓,由于使用DOM样式的方法的内存要求?)

文章Android上处理XML

SOF如何在Android

I have got a very large xml file with categories in one xml file which maps to sub categories in another xml file according to category id. The xml file with only category id and names is loading fast, but the xml file which has subcategories with images path, description, latitude-longitude etc...is taking time to load.

I am using javax.xml package and org.w3c.dom package. The list action is loading the file in each click to look for subcategories. Is there any way to make this whole process faster?

Edit-1

Heres the code i am using to getch subcategories: Document doc = this.builder.parse(inStream, null);

        doc.getDocumentElement().normalize();
        NodeList pageList = doc.getElementsByTagName("page");
        final int length = pageList.getLength();

        for (int i = 0; i < length; i++)
        {
            boolean inCategory = false;
            Element categories = (Element) getChild(pageList.item(i), "categories");


            if(categories != null)
            {
                NodeList categoryList = categories.getElementsByTagName("category");
                for(int j = 0; j < categoryList.getLength(); j++)
                {
                    if(Integer.parseInt(categoryList.item(j).getTextContent()) == catID)
                    {
                        inCategory = true;
                        break;
                    }
                }
            }

            if(inCategory == true)
            {
                final NamedNodeMap attr = pageList.item(i).getAttributes();
                //

                //get Page ID
                final int categoryID = Integer.parseInt(getNodeValue(attr, "id"));

                //get Page Name
                final String categoryName = (getChild(pageList.item(i), "title") != null) ? getChild(pageList.item(i), "title").getTextContent() : "Untitled";

                //get ThumbNail
                final NamedNodeMap thumb_attr = getChild(pageList.item(i), "thumbnail").getAttributes();
                final String categoryImage = "placethumbs/" + getNodeValue(thumb_attr, "file");

                //final String categoryImage = "androidicon.png";

                Category category = new Category(categoryName, categoryID, categoryImage);

                this.list.add(category);
                Log.d(tag, category.toString());
            }
        }

解决方案

Maybe a SAX processor would be quicker (assuming your App is slowing down due to memory requirements of using a DOM-style approach?)

Article on processing XML on android

SOF question about SAX processing on Android

这篇关于Java的Andr​​oid的非常大的XML解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆