Here you can find the source of addChildElements(Node n, List
private static void addChildElements(Node n, List<String> elements)
//package com.java2s; /*/* w w w. jav a 2 s.co m*/ * Copyright 2010-2011 the original author or authors. * * WebServiceMocker is free software; you can redistribute it and/or modify it under the * terms of version 2.1 of the GNU Lesser General Public License as published by * the Free Software Foundation. * * WebServiceMocker 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 Lesser General Public License for more details at gnu.org. */ import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { private static void addChildElements(Node n, List<String> elements) { NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { n = nl.item(i); if (n.getNodeType() != 1) { continue; } else { if (hasChild(n)) { addChildElements(n, elements); } else { if (!elements.contains(n.getLocalName())) elements.add(n.getLocalName()); } } } } private static boolean hasChild(Node n) { NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { n = nl.item(i); if (n.getNodeType() == 1) return true; } return false; } }