Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { /** * to get node's owner document * * @return The document that contain node */ public static Document getOwnerDocument(Node node) { Document doc = null; if (node.getNodeType() == Node.DOCUMENT_NODE) { doc = (Document) node; } else { doc = node.getOwnerDocument(); } return doc; } }