code: public static Node getParentOfNode(Node node)
    {
            Node parent=node.getParentNode();
            if(parent==null && (Node.ATTRIBUTE_NODE == node.getNodeType()) )
             parent=((Attr) node).getOwnerElement();
            return parent;
    }
docs: Get the XPath-model parent of a node.  This version takes advantage
  of the DOM Level 2 Attr.ownerElement() method; the base version we
  would otherwise inherit is prepared to fall back on exhaustively
  walking the document to find an Attr's parent.
  
  @param node Node to be examined
  
  @return the DOM parent of the input node, if there is one, or the
  ownerElement if the input node is an Attr, or null if the node is
  a Document, a DocumentFragment, or an orphan.