Java XML Element Sibling getNextSibling(Element h2)

Here you can find the source of getNextSibling(Element h2)

Description

get Next Sibling

License

Open Source License

Declaration

public static Element getNextSibling(Element h2) 

Method Source Code

//package com.java2s;
/**/*from   w w  w  .  ja  va2 s . co  m*/
 *  Copyright (c) 2013-2014 Angelo ZERR.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *  Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
 */

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static Element getNextSibling(Element h2) {
        Node node = h2.getNextSibling();
        while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
            node = node.getNextSibling();
        }
        return getElement(node);
    }

    public static Element getElement(Node node) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            return (Element) node;
        }
        return null;
    }
}

Related

  1. countPrecedingSiblingsOfType(Element inElem)
  2. getNextElementSibling(Element aElement)
  3. getNextSibling(Element element)
  4. getNextSibling(Element node, String name)
  5. getNextSiblingElement(Element el)
  6. getNextSiblingElement(Element elem)
  7. getNextSiblingElement(Element elem)