List of utility methods to do XML Node Parse
List | parseArray(final Node array) Utility method to parse a 'array' node of the iTunes meta pList. final List<String> arrayList = new ArrayList<>(); if (array != null && array.getNodeType() == Node.ELEMENT_NODE && "array".equals(array.getNodeName())) { final NodeList children = array.getChildNodes(); if (children != null) { for (int i = 0; i < children.getLength(); ++i) { final Node node = children.item(i); if (node != null && node.getNodeType() == Node.ELEMENT_NODE && "dict".equals(node.getNodeName())) { ... |
Map | parseDictionary(final Node dictionary) Utility method to parse a 'dict' node of the iTunes meta pList. final Map<String, List<String>> iTunesMap = new HashMap<>(); if (dictionary != null && dictionary.getNodeType() == Node.ELEMENT_NODE && "dict".equals(dictionary.getNodeName())) { final NodeList children = dictionary.getChildNodes(); if (children != null) { String key = null; List<String> value = null; for (int i = 0; i < children.getLength(); ++i) { ... |
int | parseInt(Node node) parse Int Objects.requireNonNull(node); if (!node.getNodeName().equalsIgnoreCase("int")) { throw new IllegalArgumentException("Node is not int: " + node); return Integer.parseInt(node.getTextContent()); |
Integer[] | parseIntervals(Node intervals) parse Intervals NodeList sc = intervals.getChildNodes(); int len = sc.getLength(); int[] a = new int[len]; List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < len; i++) { Node nn = sc.item(i); if (nn.getNodeName().equalsIgnoreCase("interval")) { a[i] = Integer.parseInt(nn.getTextContent()); ... |
List | parseList(Node node) parse List Objects.requireNonNull(node); if (!node.getNodeName().equalsIgnoreCase("list")) { throw new IllegalArgumentException("Node is not list: " + node); int n = node.getChildNodes().getLength(); List<Node> nodes = new ArrayList<>(n); for (int i = 0; i < n; i++) { nodes.add(node.getChildNodes().item(i)); ... |
void | parseModule(Node module, PrintWriter out) Parses a giving module and writes it into the giving output stream ArrayList<Node> nodes = getNodesByName("Implements", module.getChildNodes()); if (nodes.size() == 0) { System.out.println("Error: Module " + getAttributeValue(module, "name") + " does not contain an IMPLEMENTS element!"); return; for (int i = 0; i < nodes.size(); i++) { String root = getAttributeValue(nodes.get(i), "name1"); ... |
Node | parseOptionNode(Node node) parse Option Node Objects.requireNonNull(node); if (!(node instanceof Element) || !node.getNodeName().equalsIgnoreCase("option")) { throw new IllegalArgumentException("Node is not option: " + node); Element e = (Element) node; if (e.hasAttribute("val")) { String val = e.getAttribute("val"); if (val.equalsIgnoreCase("some")) { ... |
String | parseOptionString(Node node) parse Option String Node str = parseOptionNode(node); if (str == null) { return null; } else { return parseString(str); |
Node | parsePairFirst(Node node) parse Pair First Objects.requireNonNull(node); if (!node.getNodeName().equalsIgnoreCase("pair")) { throw new IllegalArgumentException("Node is not pair: " + node); if (node.getChildNodes().getLength() != 2) { throw new IllegalArgumentException("Malformed pair: " + node); return node.getFirstChild(); ... |
Map | parseProperties(Node doc) Parse the childnodes of a node and look for <property> elements with attributes name and value. NodeList propertyNodes = doc.getChildNodes(); Map<String, String> properties = new HashMap<String, String>(); for (int i = 0; i < propertyNodes.getLength(); i++) { Node node = propertyNodes.item(i); if (node.getNodeName().equals("property")) { String key = node.getAttributes().getNamedItem("name").getNodeValue(); String value = node.getAttributes().getNamedItem("value").getNodeValue(); properties.put(key, value); ... |