XMLParser.java

  1. package org.opentrafficsim.road.network.factory.opendrive;

  2. import java.util.ArrayList;
  3. import java.util.List;

  4. import org.w3c.dom.Element;
  5. import org.w3c.dom.Node;
  6. import org.w3c.dom.NodeList;

  7. /**
  8.  * <p>
  9.  * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  10.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  11.  * <p>
  12.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  13.  * initial version Jul 23, 2015 <br>
  14.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  15.  */
  16. public final class XMLParser
  17. {
  18.     /** Utility class. */
  19.     private XMLParser()
  20.     {
  21.         // do not instantiate
  22.     }

  23.     /**
  24.      * @param nodeList NodeList; the list of nodes to process
  25.      * @param tag String; the tag to look for, e.g., LINK
  26.      * @return the nodes (which can contain nodeLists themselves) with the given tag
  27.      */
  28.     public static List<Node> getNodes(final NodeList nodeList, final String tag)
  29.     {
  30.         List<Node> result = new ArrayList<>();
  31.         for (int i = 0; i < nodeList.getLength(); i++)
  32.         {
  33.             Node node = nodeList.item(i);
  34.             if (node instanceof Element)
  35.             {
  36.                 if (tag.equals(node.getNodeName()))
  37.                 {
  38.                     result.add(node);
  39.                 }
  40.             }
  41.         }
  42.         return result;
  43.     }
  44. }