src/main/java/org/jsoup/helper/W3CDom.java
/**
     * Convert a jsoup DOM to a W3C Document. The created nodes will link back to the original
     * jsoup nodes in the user property {@link #SourceProperty} (but after conversion, changes on one side will not
     * flow to the other). The input Element is used as a context node, but the whole surrounding jsoup Document is
     * converted. (If you just want a subtree converted, use {@link #convert(org.jsoup.nodes.Element, Document)}.)
     *
     * @param in jsoup element or doc
     * @return a W3C DOM Document representing the jsoup Document or Element contents.
     * @see #sourceNodes(NodeList, Class)
     * @see #contextNode(Document)
     */
Convert a jsoup DOM to a W3C Document. The created nodes will link back to the original
jsoup nodes in the user property  #SourceProperty (but after conversion, changes on one side will not
flow to the other). The input Element is used as a context node, but the whole surrounding jsoup Document is
converted. (If you just want a subtree converted, use  #convert(org.jsoup.nodes.Element, Document).)

@param in jsoup element or doc
@return a W3C DOM Document representing the jsoup Document or Element contents.
Convert a jsoup DOM to a W3C Document . The created nodes will link back to the original jsoup nodes in the user property #SourceProperty ( but after conversion changes on one side will not flow to the other ) . The input Element is used as a context node but the whole surrounding jsoup Document is converted . ( If you just want a subtree converted use #convert ( org . jsoup . nodes . Element Document ) . ) @param in jsoup element or doc @return a W3C DOM Document representing the jsoup Document or Element contents .
public Document fromJsoup(org.jsoup.nodes.Element in) {
        Validate.notNull(in);
        DocumentBuilder builder;
        try {
            builder = factory.newDocumentBuilder();
            DOMImplementation impl = builder.getDOMImplementation();
            Document out = builder.newDocument();
            org.jsoup.nodes.Document inDoc = in.ownerDocument();
            org.jsoup.nodes.DocumentType doctype = inDoc != null ? inDoc.documentType() : null;
            if (doctype != null) {
                org.w3c.dom.DocumentType documentType = impl.createDocumentType(doctype.name(), doctype.publicId(), doctype.systemId());
                out.appendChild(documentType);
            }
            out.setXmlStandalone(true);
            org.jsoup.nodes.Element context = (in instanceof org.jsoup.nodes.Document) ? in.child(0) : in;
            out.setUserData(ContextProperty, context, null);
            convert(inDoc != null ? inDoc : in, out);
            return out;
        } catch (ParserConfigurationException e) {
            throw new IllegalStateException(e);
        }
    }
public Document fromJsoup ( org . jsoup . nodes . Element in ) { Validate . notNull ( in ) ; DocumentBuilder builder ; try { builder = factory . newDocumentBuilder ( ) ; DOMImplementation impl = builder . getDOMImplementation ( ) ; Document out = builder . newDocument ( ) ; org . jsoup . nodes . Document inDoc = in . ownerDocument ( ) ; org . jsoup . nodes . DocumentType doctype = inDoc != null ? inDoc . documentType ( ) : null ; if ( doctype != null ) { org . w3c . dom . DocumentType documentType = impl . createDocumentType ( doctype . name ( ) , doctype . publicId ( ) , doctype . systemId ( ) ) ; out . appendChild ( documentType ) ; } out . setXmlStandalone ( true ) ; org . jsoup . nodes . Element context = ( in instanceof org . jsoup . nodes . Document ) ? in . child ( 0 ) : in ; out . setUserData ( ContextProperty , context , null ) ; convert ( inDoc != null ? inDoc : in , out ) ; return out ; } catch ( ParserConfigurationException e ) { throw new IllegalStateException ( e ) ; } }
Convert a jsoup DOM to a W3C Document.
Convert a jsoup DOM to a W3C Document .
// if in is Document, use the root element, not the wrapping document, as the context: