DOM SAXReader
下面是一个例子:
try { SAXReader reader = new SAXReader(); Element root = reader.read(levelFilePath).getRootElement(); List<Element> typeList = root.elements(); for (Element typeElement : typeList) { List<Element> firstLevelList = typeElement.elements(); for (Element firstLevelElement : firstLevelList) { List<String> secondLevelNames = new ArrayList<String>(); List<Element> secondLevelList = firstLevelElement.elements(); for (Element secondLevelElement : secondLevelList) { secondLevelNames.add(secondLevelElement.attributeValue("name")); } levelMap.put(firstLevelElement.attributeValue("name"), secondLevelNames); } } } catch (Exception e) { LOGGER.error("获取类别信息文件出错", e); }