get Pre Homo Sibling from XML Node - Java XML

Java examples for XML:XML Element Parent

Description

get Pre Homo Sibling from XML Node

Demo Code


//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    public static Node getPreHomoSibling(Node aNode) {
        Node preSibling = aNode;/*from  w w  w  .j  a  va2s .  c om*/
        while ((preSibling = preSibling.getPreviousSibling()) != null) {
            //System.out.println("preSibling name: "+preSibling.getNodeName()+" "+preSibling.getTextContent());
            if (preSibling.getNodeName().equals(aNode.getNodeName())) {
                return preSibling;
            }
        }
        return null;
    }
}

Related Tutorials