NodeList nList2 = doc.getElementsByTagName("dep");
Map<String, List<Map<String, String>>> depMap = new HashMap<String, List<Map<String, String>>>();
for (int temp = 0; temp < nList2.getLength(); temp++) {
Element el = (Element)nList2.item(temp);
String type=el.getAttribute("type");
Node nNode = nList2.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
List<Map<String,String>> depList = new ArrayList<Map<String,String>>();
String governor = getTagValue("governor", eElement);
String dependent = getTagValue("dependent", eElement);
Map<String, String> govdepmap = new HashMap<String, String>();
govdepmap.put(governor, dependent);
depList.add(govdepmap);
List<Map<String,String>> flist = new ArrayList<Map<String,String>>();
flist.add(govdepmap);
depMap.put(type, flist);
}
}
我的 XML 文件中有以下结构:
<basic-dependencies>
<dep type="nsubj">
<governor idx="4">going</governor>
<dependent idx="1">I</dependent>
</dep>
现在我想存储每个“州长”和“依赖”标签的“idx”属性。我应该更改或添加什么代码?