Get parent : DOM Search « XML « Java






Get parent

 

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



public class Main {

  public static Element getParent(Element elem) {
      Node parent = elem.getParentNode();
      if (parent instanceof Element)
          return (Element)parent;
      return null;
  } // getParent(Element):Element

 
}

   
  








Related examples in the same category

1.Finds and returns the first child element node.
2.Finds and returns the first child node with the given name and attribute name, value pair.
3.Finds and returns the first child node with the given name.
4.Finds and returns the first child node with the given qualified name.
5.Finds and returns the last child element node.
6.Finds and returns the last child node with the given name and attribute name, value pair.
7.Finds and returns the last child node with the given name.
8.Finds and returns the last child node with the given qualified name.
9.Finds and returns the next sibling element node.
10.Finds and returns the next sibling node with the given name and attribute name, value pair.
11.Finds and returns the next sibling node with the given name.
12.Finds and returns the next sibling node with the given qualified name.