List of utility methods to do XML Node Sibiling
Node | getPreviousSiblingByName(Node currentNode, String tagName) Search earlier siblings for a given node Node node = currentNode.getPreviousSibling(); while ((node != null) && (!node.getNodeName().equals(tagName))) { node = node.getPreviousSibling(); return node; |
Node | getPreviousSiblingElement(Node node) get Previous Sibling Element if (node == null) return null; Node prevSibling = node.getPreviousSibling(); while ((prevSibling != null) && (prevSibling.getNodeType() != Node.ELEMENT_NODE)) prevSibling = prevSibling.getPreviousSibling(); if ((prevSibling != null) && (prevSibling.getNodeType() == Node.ELEMENT_NODE)) return prevSibling; return null; ... |
Element | getPreviousSiblingElement(Node node) Get the previous sibling element. Node n = node.getPreviousSibling(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) { n = n.getPreviousSibling(); return (Element) n; |
Node | getSibling(Node current) Get the sibling in next context Node sibling = current.getNextSibling(); Node tmpParent = current; while (tmpParent != null && sibling == null) { tmpParent = tmpParent.getParentNode(); if (tmpParent != null) { sibling = tmpParent.getNextSibling(); return sibling; |
Map | getSiblingValues(Node currentNode, Set This method looks at the siblings of a given node, matches the ones in the passed Set, then returns a map of the matches with their values Map<String, String> responseMap = new HashMap<String, String>(); String testString = currentNode.getLocalName().toLowerCase(); for (String tagName : siblingTags) { if (testString.contains(tagName.toLowerCase())) { responseMap.put(tagName, currentNode.getTextContent().trim()); return responseMap; return responseMap; |