Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;
import java.util.HashMap;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static ArrayList<HashMap<String, String>> getWhoList(Node currentNode, String tagName) {
        String result = "";
        ArrayList<HashMap<String, String>> whoArrayList = new ArrayList<HashMap<String, String>>();
        NodeList childNodeList = currentNode.getChildNodes();
        for (int i = 0; i < childNodeList.getLength(); i++) {
            Node childNode = childNodeList.item(i);
            if (childNode.getNodeName().equals(tagName)) {
                HashMap<String, String> whoMap = new HashMap<String, String>();
                NamedNodeMap attrNodeMap = childNode.getAttributes();
                Node activity = attrNodeMap.getNamedItem("activity");
                Node email = attrNodeMap.getNamedItem("email");
                Node name = attrNodeMap.getNamedItem("name");
                if (activity != null) {
                    whoMap.put("activity", activity.getNodeValue());
                }
                if (email != null) {
                    whoMap.put("email", email.getNodeValue());
                }
                if (name != null) {
                    whoMap.put("name", name.getNodeValue());
                }
                whoArrayList.add(whoMap);
            }
        }
        return whoArrayList;
    }
}