List of utility methods to do XML Node Name
Node | getNode(Node node, String nodeName) get Node if (node.getNodeType() == Node.ELEMENT_NODE) { Element el = (Element) node; NodeList nodeList = el.getElementsByTagName(nodeName); if (nodeList.getLength() > 0) { return nodeList.item(0); return null; ... |
Node | getNode(Node node, String nodeName) get Node List<Node> childList = getChildNodesByName(node, nodeName); if (childList.size() > 0) { return childList.get(0); } else { return null; |
Optional | getNodeContent(Node item, String nodeName) Gets the content of a subnode. if (item.getNodeType() != Node.ELEMENT_NODE) { return Optional.empty(); NodeList metadata = ((Element) item).getElementsByTagName(nodeName); if (metadata.getLength() == 1) { return Optional.ofNullable(metadata.item(0).getTextContent()); } else { return Optional.empty(); ... |
String | getNodeContent(Node n, String nodename) get Node Content Node r = getNode(n, nodename); if (r != null) return r.getTextContent(); else return null; |
String | getNodeName(Node node) Get the non qualified tag name String localName = node.getLocalName(); if (localName != null) { return localName; String name = node.getNodeName(); int idx = name.indexOf(":"); if (idx >= 0) { name = name.substring(idx + 1); ... |
String | getNodeName(Node node) get Node Name if (node == null) { System.out.println("node is null"); return ""; String name = node.getNodeName(); if (name == null) { System.out.println("name is null"); return ""; ... |
String | getNodeName(Node node) get Node Name String name = node.getLocalName(); if (name == null) name = node.getNodeName(); return name; |
String | getNodeName(Node node) get Node Name String name = ""; NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node curNode = nodeList.item(i); if ("name".equalsIgnoreCase(curNode.getNodeName())) { name = curNode.getTextContent().replace("\"", ""); break; return name; |
String | getNodeName(Node node) get Node Name String name = node.getNamespaceURI() != null ? node.getLocalName() : node.getNodeName(); if (name.contains(":")) { String[] parts = name.split(":"); name = parts[parts.length - 1]; return name; |
String | getNodeNameIgnorePrefix(Node node) get node name without any prefix if (node == null) return null; String nodeName = node.getNodeName(); if (nodeName.contains(":")) { nodeName = nodeName.split(":")[1]; return nodeName; |