Class DocumentReader

java.lang.Object
org.opentrafficsim.editor.DocumentReader

public final class DocumentReader extends Object
Utility class to read XSD or XML from URI. There are also methods to obtain certain information from a node.

Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Wouter Schakel
  • Method Details

    • open

      Opens an XSD or XML file.
      Parameters:
      file - file.
      Returns:
      document, i.e. the root of the XSD file.
      Throws:
      SAXException - exception
      IOException - exception
      ParserConfigurationException - exception
    • getAttribute

      public static Optional<String> getAttribute(Node node, String name)
      Returns the attribute of a node. This is short for:
       Optional.ofNullable(node.hasAttributes() && node.getAttributes().getNamedItem(name) != null
               ? node.getAttributes().getNamedItem(name).getNodeValue() : null);
       
      Parameters:
      node - node.
      name - attribute name.
      Returns:
      value of the attribute in the node.
    • getChild

      public static Optional<Node> getChild(Node node, String type)
      Returns a child node of specified type. It should be a type of which there may be only one.
      Parameters:
      node - node
      type - child type, e.g. xsd:complexType.
      Returns:
      child node of specified type, empty if no such child.
    • getChildren

      public static List<Node> getChildren(Node node, String type)
      Returns child nodes of specified type.
      Parameters:
      node - node
      type - child type, e.g. xsd:field.
      Returns:
      child nodes of specified type, empty List of no such child.
    • filterHtml

      public static String filterHtml(String string)
      Remove HTML tags from string.
      Parameters:
      string - input string
      Returns:
      string with HTML tags removed, or null if the input is null