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 - URI; file.
      Returns:
      Document; document, i.e. the root of the XSD file.
      Throws:
      SAXException - exception
      IOException - exception
      ParserConfigurationException - exception
    • getAnnotation

      public static String getAnnotation(Node node, String element, String source)
      Returns an annotation value. These are defined as below, for either xsd:appinfo or xsd:documentation. All space-like characters are replaced by blanks, and consecutive blanks are removed.
       <xsd:sequence>
         <xsd:annotation>
           <xsd:appinfo source="name">annotates the sequence</xsd:appinfo>
         </xsd:annotation>
       </xsd:sequence>
       
      Parameters:
      node - Node; node, either xsd:element or xsd:attribute.
      element - String; either "xsd:documentation" or "xsd:appinfo".
      source - String; name that the source attribute of the annotation should have.
      Returns:
      String; annotation value, null if not found.
    • getAttribute

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

      public static 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 node;
      type - String; child type, e.g. xsd:complexType.
      Returns:
      Node; child node of specified type.
    • getChildren

      public static ArrayList<Node> getChildren(Node node, String type)
      Returns child nodes of specified type.
      Parameters:
      node - Node node;
      type - String; child type, e.g. xsd:field.
      Returns:
      ArayList<Node>; child nodes of specified type.