Java XML Node Sibiling getLocHomoSibling(Node aNode)

Here you can find the source of getLocHomoSibling(Node aNode)

Description

aims at finding the location of the current node of its kind.

License

Apache License

Parameter

Parameter Description
aNode a parameter

Declaration

public static int getLocHomoSibling(Node aNode) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Node;

public class Main {
    /**//www .j  a v  a  2 s . c  o  m
     * aims at finding the location of the current node of its kind. the idea is
     * to count how many previous siblings does it have,
     * 
     * @param aNode
     * @return
     */
    public static int getLocHomoSibling(Node aNode) {
        int countOfBranch = 0;
        Node preSibling = aNode;
        while ((preSibling = preSibling.getPreviousSibling()) != null) {
            if (preSibling.getNodeName().equals(aNode.getNodeName())) {
                countOfBranch++;
            }
        }
        return countOfBranch;
    }
}

Related

  1. containsSiblings(org.w3c.dom.Node node)
  2. getFirstElementSibling(Node node)
  3. getFirstSiblingElmt(Node aNode)
  4. getFirstSiblingNamed(Node node, String name)
  5. getNextElementSibling(Node node)
  6. getNextElementSibling(Node node)
  7. getNextElementSibling(Node node)
  8. getNextHomoSibling(Node aNode)