javaxmlw3cdom4j

convert dom4j docment to W3c document


I need to convert XML built with dom4j to a w3c document and don't have any idea about how do it.


Solution

  • I'm assuming you want to go from:

    org.dom4j.Document
    

    To:

    org.w3c.dom.Document
    

    From the dom4j quick start guide:

    Document document = ...;
    String text = document.asXML();
    

    From a JavaRanch example on String to Document:

    public static Document stringToDom(String xmlSource) 
            throws SAXException, ParserConfigurationException, IOException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(new InputSource(new StringReader(xmlSource)));
    }
    

    Combine the 2 and you should have what you need.