2011-09-07 94 views
0

我有一个非常大的xml文件,其中一个xml文件中的类别根据类别id映射到另一个xml文件中的子类别。只有类别id和名称的xml文件加载速度很快,但具有图像路径,描述,纬度经度等子类的xml文件正在花费时间加载。java android非常大的xml解析

我使用javax.xml包和org.w3c.dom包。 列表操作是在每次单击时加载文件以查找子类别。 有什么办法可以使整个过程更快?

编辑-1

赫雷什我使用的参考getch子类别的代码: 文献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()); 
      } 
     } 
+1

我们展示我们的代码访问子类别 –

回答

3

使用基于SAX的解析器,DOM不适合大型xml。