File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
src/main/java/org/scijava/util Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 3939import java .io .PrintStream ;
4040import java .io .StringWriter ;
4141import java .net .URL ;
42+ import java .util .ArrayList ;
4243
4344import javax .xml .parsers .DocumentBuilder ;
4445import javax .xml .parsers .DocumentBuilderFactory ;
5657import javax .xml .xpath .XPathFactory ;
5758
5859import org .w3c .dom .Document ;
60+ import org .w3c .dom .Element ;
5961import org .w3c .dom .Node ;
6062import org .w3c .dom .NodeList ;
6163import org .xml .sax .SAXException ;
@@ -184,6 +186,19 @@ public String cdata(final String expression) {
184186 return cdata (nodes .item (0 ));
185187 }
186188
189+ /** Obtains the elements identified by the given XPath expression. */
190+ public ArrayList <Element > elements (final String expression ) {
191+ final NodeList nodes = xpath (expression );
192+ final ArrayList <Element > elements = new ArrayList <Element >();
193+ if (nodes != null ) {
194+ for (int i =0 ; i <nodes .getLength (); i ++) {
195+ final Node node = nodes .item (i );
196+ if (node instanceof Element ) elements .add ((Element ) node );
197+ }
198+ }
199+ return elements ;
200+ }
201+
187202 /** Obtains the nodes identified by the given XPath expression. */
188203 public NodeList xpath (final String expression ) {
189204 final Object result ;
You can’t perform that action at this time.
0 commit comments