XML parsing by DOM

Posted by blackpearl on Stack Overflow See other posts from Stack Overflow or by blackpearl
Published on 2012-07-05T09:13:52Z Indexed on 2012/07/05 9:15 UTC
Read the original article Hit count: 286

Filed under:
|
|
    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);
      }
    }

I have the following structure in my XML file: going I

Now i want to store the "idx" attribute of each "governor" and "dependent" tag. What code should I change or add?

© Stack Overflow or respective owner

Related posts about java

Related posts about Xml