Code example for Node

Methods: getFirstChild

0
 
    public static Node getNodeAtPosition(Node parent, int offset) {
        if(offset <0) {
            return null; 
        } else if (offset == 0) {
            return parent.getFirstChild();
        } 
        NodeList nodes = parent.getChildNodes();
        int count = nodes.getLength();
        if(offset < count) {
            return nodes.item(offset);
        } 
        return null; 
    } 
 
    public static int getNodePosition(Node node) {
        int pos = -1;
        while(node != null) {
            ++pos;
            node = node.getPreviousSibling();