Package org.opentrafficsim.editor
Class DocumentReader
java.lang.Object
org.opentrafficsim.editor.DocumentReader
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 Summary
Modifier and TypeMethodDescriptionstatic String
getAnnotation
(Node node, String element, String source) Returns an annotation value.static String
getAttribute
(Node node, String name) Returns the attribute of a node.static Node
Returns a child node of specified type.getChildren
(Node node, String type) Returns child nodes of specified type.static Document
Opens an XSD or XML file.
-
Method Details
-
open
public static Document open(URI file) throws SAXException, IOException, ParserConfigurationException Opens an XSD or XML file.- Parameters:
file
- URI; file.- Returns:
- Document; document, i.e. the root of the XSD file.
- Throws:
SAXException
- exceptionIOException
- exceptionParserConfigurationException
- exception
-
getAnnotation
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
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
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
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.
-