Java Utililty Methods XML Node Next

List of utility methods to do XML Node Next

Description

The list of methods to do XML Node Next are organized into topic(s).

Method

NodegetNext(final Node current, final boolean sameName)
get Next
String name = null;
if (sameName) {
    name = current.getNodeName();
int type = current.getNodeType();
return getNext(current, name, type);
NodegetNext(Node current)
Get the next sibling with the same name and type
String name = current.getNodeName();
int type = current.getNodeType();
return getNext(current, name, type);
NodegetNext(Node current, String name, int type)
Return the next sibling with a given name and type
Node first = current.getNextSibling();
if (first == null)
    return null;
for (Node node = first; node != null; node = node.getNextSibling()) {
    if (type >= 0 && node.getNodeType() != type)
        continue;
    if (name == null)
        return node;
...
NodegetNext(Node node)
Get the next node in a depth first preorder traversal.
if (node == null)
    return null;
if (node.getFirstChild() != null)
    return node.getFirstChild();
for (; node != null; node = node.getParentNode()) {
    if (node.getNextSibling() != null)
        return node.getNextSibling();
return null;
StringgetNextComment(Node element)
Gets the next comment.
while (element.getNextSibling() != null) {
    Node prev = element.getNextSibling();
    if (prev.getNodeType() == Node.COMMENT_NODE) {
        return prev.getTextContent();
    } else if (prev.getNodeType() == Node.TEXT_NODE) {
        return getNextComment(prev);
    } else if (prev.getNodeType() == Node.ELEMENT_NODE) {
        return null;
...
StringgetNextComment(Node element)
get Next Comment
while (element.getNextSibling() != null) {
    Node prev = element.getNextSibling();
    if (prev.getNodeType() == Node.COMMENT_NODE) {
        return prev.getTextContent();
    } else if (prev.getNodeType() == Node.TEXT_NODE) {
        return getNextComment(prev);
    } else if (prev.getNodeType() == Node.ELEMENT_NODE) {
        return null;
...
ElementgetNextElement(Node el)
get Next Element
Node node = el;
while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
    node = node.getNextSibling();
return (Element) node;
ElementgetNextElement(Node node)
Get the next right sibling that is an element.
Element found = null;
if (node != null) {
    for (Node next = node.getNextSibling(); next != null && found == null; next = next.getNextSibling()) {
        if (next.getNodeType() == Node.ELEMENT_NODE) {
            found = (Element) next;
return found;
ElementgetNextElement(Node node)
get Next Element
node = node.getNextSibling();
while (node != null) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) node;
    node = node.getNextSibling();
return null;
...
NodegetNextElement(Node node)
Get a sibling XML element of a given node.
Node child = node.getNextSibling();
if (child == null)
    return null;
if (child.getNodeType() == Node.ELEMENT_NODE)
    return child;
while (child != null) {
    if (child.getNodeType() == Node.ELEMENT_NODE)
        return child;
...