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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumTypes of annotation elements theDocumentReadercan read. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringfilterHtml(String string) Remove HTML tags from string.getAttribute(Node node, String name) Returns the attribute of a node.Returns a child node of specified type.getChildren(Node node, String type) Returns child nodes of specified type.static DocumentOpens 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- file.- Returns:
- document, i.e. the root of the XSD file.
- Throws:
SAXException- exceptionIOException- exceptionParserConfigurationException- exception
-
getAttribute
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
Returns a child node of specified type. It should be a type of which there may be only one.- Parameters:
node- nodetype- child type, e.g. xsd:complexType.- Returns:
- child node of specified type, empty if no such child.
-
getChildren
Returns child nodes of specified type.- Parameters:
node- nodetype- child type, e.g. xsd:field.- Returns:
- child nodes of specified type, empty
Listof no such child.
-
filterHtml
Remove HTML tags from string.- Parameters:
string- input string- Returns:
- string with HTML tags removed, or
nullif the input isnull
-