【发布时间】:2011-09-07 10:41:15
【问题描述】:
我有一个非常大的 xml 文件,其中一个 xml 文件中的类别根据类别 ID 映射到另一个 xml 文件中的子类别。只有类别 id 和名称的 xml 文件加载速度很快,但包含图像路径、描述、经纬度等子类别的 xml 文件需要时间来加载。
我正在使用 javax.xml 包和 org.w3c.dom 包。 列表操作是在每次单击时加载文件以查找子类别。 有什么办法可以加快整个过程?
编辑-1
这是我用来获取子类别的代码: 文档 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());
}
}
【问题讨论】:
-
向我们展示访问子类别的代码