Java tutorial
//package com.java2s; /* // This software is subject to the terms of the Eclipse Public License v1.0 // Agreement, available at the following URL: // http://www.eclipse.org/legal/epl-v10.html. // You must accept the terms of that agreement to use this software. // // Copyright (C) 2003-2005 Julian Hyde // Copyright (C) 2005-2011 Pentaho // Copyright (c) 2008-2014 Open Link Financial, Inc. All Rights Reserved. */ import org.w3c.dom.*; import java.util.*; public class Main { public static Element[] filterChildElements(Element parent, String ns, String lname) { List<Element> elems = new ArrayList<Element>(); NodeList nlst = parent.getChildNodes(); for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) { Node n = nlst.item(i); if (n instanceof Element) { Element e = (Element) n; if ((ns == null || ns.equals(e.getNamespaceURI())) && (lname == null || lname.equals(e.getLocalName()))) { elems.add(e); } } } return elems.toArray(new Element[elems.size()]); } }