Class W3CDom


  • public class W3CDom
    extends java.lang.Object
    Helper class to transform a Document to a org.w3c.dom.Document, for integration with toolsets that use the W3C DOM.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  W3CDom.W3CBuilder
      Implements the conversion by walking the input.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.xml.parsers.DocumentBuilderFactory factory  
    • Constructor Summary

      Constructors 
      Constructor Description
      W3CDom()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String asString​(org.w3c.dom.Document doc)
      Serialize a W3C document to a String.
      static java.lang.String asString​(org.w3c.dom.Document doc, java.util.Map<java.lang.String,​java.lang.String> properties)
      Serialize a W3C document to a String.
      static org.w3c.dom.Document convert​(Document in)
      Converts a jsoup DOM to a W3C DOM
      void convert​(Document in, org.w3c.dom.Document out)
      Converts a jsoup document into the provided W3C Document.
      org.w3c.dom.Document fromJsoup​(Document in)
      Convert a jsoup Document to a W3C Document.
      static java.util.HashMap<java.lang.String,​java.lang.String> OutputHtml()
      Canned default for HTML output.
      static java.util.HashMap<java.lang.String,​java.lang.String> OutputXml()
      Canned default for XML output.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • factory

        protected javax.xml.parsers.DocumentBuilderFactory factory
    • Constructor Detail

      • W3CDom

        public W3CDom()
    • Method Detail

      • convert

        public static org.w3c.dom.Document convert​(Document in)
        Converts a jsoup DOM to a W3C DOM
        Parameters:
        in - jsoup Document
        Returns:
        W3C Document
      • asString

        public static java.lang.String asString​(org.w3c.dom.Document doc,
                                                @Nullable
                                                java.util.Map<java.lang.String,​java.lang.String> properties)
        Serialize a W3C document to a String. Provide Properties to define output settings including if HTML or XML. If you don't provide the properties (null), the output will be auto-detected based on the content of the document.
        Parameters:
        doc - Document
        properties - (optional/nullable) the output properties to use. See Transformer.setOutputProperties(Properties) and OutputKeys
        Returns:
        Document as string
        See Also:
        OutputHtml(), OutputXml(), OutputKeys.ENCODING, OutputKeys.OMIT_XML_DECLARATION, OutputKeys.STANDALONE, OutputKeys.STANDALONE, OutputKeys.DOCTYPE_PUBLIC, OutputKeys.DOCTYPE_PUBLIC, OutputKeys.CDATA_SECTION_ELEMENTS, OutputKeys.INDENT, OutputKeys.MEDIA_TYPE
      • OutputHtml

        public static java.util.HashMap<java.lang.String,​java.lang.String> OutputHtml()
        Canned default for HTML output.
      • OutputXml

        public static java.util.HashMap<java.lang.String,​java.lang.String> OutputXml()
        Canned default for XML output.
      • fromJsoup

        public org.w3c.dom.Document fromJsoup​(Document in)
        Convert a jsoup Document to a W3C Document.
        Parameters:
        in - jsoup doc
        Returns:
        w3c doc
      • convert

        public void convert​(Document in,
                            org.w3c.dom.Document out)
        Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document before converting.
        Parameters:
        in - jsoup doc
        out - w3c doc
        See Also:
        fromJsoup(org.jsoup.nodes.Document)
      • asString

        public java.lang.String asString​(org.w3c.dom.Document doc)
        Serialize a W3C document to a String. The output format will be XML or HTML depending on the content of the doc.
        Parameters:
        doc - Document
        Returns:
        Document as string
        See Also:
        asString(Document, Map)