Java tutorial
//package com.java2s; /** * e-Science Central * Copyright (C) 2008-2013 School of Computing Science, Newcastle University * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation at: * http://www.gnu.org/licenses/gpl-2.0.html * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA. */ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.Properties; public class Main { /** Extract all of the child nodes as a Properties object from a node in an XML document */ public static Properties extractChildNodes(Document document) { try { Properties props = new Properties(); Element top = document.getDocumentElement(); NodeList children = top.getChildNodes(); Node child; String name; String value; for (int i = 0; i < children.getLength(); i++) { child = children.item(i); name = child.getNodeName(); value = child.getTextContent().trim(); props.setProperty(name, value); } return props; } catch (Exception e) { return new Properties(); } } }