0

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());
            }
        }
Community
  • 1
  • 1
Maverick
  • 2,738
  • 24
  • 91
  • 157

2 Answers2

3

Use SAX based parser, DOM is not good for large xml.

Rahul Choudhary
  • 3,789
  • 2
  • 30
  • 30
1

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

Community
  • 1
  • 1
monojohnny
  • 5,894
  • 16
  • 59
  • 83
  • how about woodstox? I read it here in stackoverflow that its quite faster.. is that the thing i am looking for? – Maverick Sep 07 '11 at 10:47