View Javadoc
1   package org.opentrafficsim.road.network.factory.opendrive;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.w3c.dom.Element;
7   import org.w3c.dom.Node;
8   import org.w3c.dom.NodeList;
9   
10  /**
11   * <p>
12   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * <p>
15   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
16   * initial version Jul 23, 2015 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public final class XMLParser
20  {
21      /** Utility class. */
22      private XMLParser()
23      {
24          // do not instantiate
25      }
26  
27      /**
28       * @param nodeList NodeList; the list of nodes to process
29       * @param tag String; the tag to look for, e.g., LINK
30       * @return the nodes (which can contain nodeLists themselves) with the given tag
31       */
32      public static List<Node> getNodes(final NodeList nodeList, final String tag)
33      {
34          List<Node> result = new ArrayList<>();
35          for (int i = 0; i < nodeList.getLength(); i++)
36          {
37              Node node = nodeList.item(i);
38              if (node instanceof Element)
39              {
40                  if (tag.equals(node.getNodeName()))
41                  {
42                      result.add(node);
43                  }
44              }
45          }
46          return result;
47      }
48  }