Java tutorial
//package com.java2s; import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Map<String, Object> getProperties(Element paramElement) { HashMap<String, Object> localHashMap = new HashMap<String, Object>(); Element[] arrayOfElement = getChildrenByName(paramElement, "property"); for (int i = 0; i < arrayOfElement.length; ++i) { String str1 = arrayOfElement[i].getAttribute("name"); String str2 = arrayOfElement[i].getAttribute("type"); String str3 = getText(arrayOfElement[i]); try { Class<?> localClass = Class.forName(str2); Constructor<?> localConstructor = localClass.getConstructor(new Class[] { String.class }); Object localObject = localConstructor.newInstance(new Object[] { str3 }); localHashMap.put(str1, localObject); } catch (Exception localException) { System.err.println( "Unable to parse property '" + str1 + "'='" + str3 + "': " + localException.toString()); } } return localHashMap; } public static Element[] getChildrenByName(Element element, String paramString) { NodeList localNodeList = element.getChildNodes(); int i = localNodeList.getLength(); LinkedList<Node> nodes = new LinkedList<Node>(); for (int j = 0; j < i; ++j) { Node localNode = localNodeList.item(j); if ((localNode.getNodeType() != 1) || (!localNode.getNodeName().equals(paramString))) continue; nodes.add(localNode); } return (Element[]) nodes.toArray(new Element[nodes.size()]); } public static String getAttribute(Element paramElement, String paramString) { return paramElement.getAttribute(paramString); } public static String getText(Element paramElement) { NodeList localNodeList = paramElement.getChildNodes(); int i = localNodeList.getLength(); for (int j = 0; j < i; ++j) { Node localNode = localNodeList.item(j); if (localNode.getNodeType() == 3) return localNode.getNodeValue(); } return ""; } }