public class

Document

extends Element
java.lang.Object
   ↳ org.jsoup.nodes.Node
     ↳ org.jsoup.nodes.Element
       ↳ org.jsoup.nodes.Document

Class Overview

A HTML Document.

Summary

Nested Classes
class Document.OutputSettings A Document's output settings control the form of the text() and html() methods. 
Public Constructors
Document(String baseUri)
Create a new, empty Document.
Public Methods
Element body()
Accessor to the document's body element.
Document clone()
Create a stand-alone, deep copy of this node, and all of its children.
Element createElement(String tagName)
Create a new Element, with this document's base uri.
static Document createShell(String baseUri)
Create a valid, empty shell of a document, suitable for adding more elements to.
Element head()
Accessor to the document's head element.
String nodeName()
Get the node name of this node.
Document normalise()
Normalise the document.
String outerHtml()
Get the outer HTML of this node.
Document.OutputSettings outputSettings()
Get the document's current output settings.
Element text(String text)
Set the text of the body of this document.
String title()
Get the string contents of the document's title element.
void title(String title)
Set the document's title element.
[Expand]
Inherited Methods
From class org.jsoup.nodes.Element
From class org.jsoup.nodes.Node
From class java.lang.Object

Public Constructors

public Document (String baseUri)

Create a new, empty Document.

Parameters
baseUri base URI of document

Public Methods

public Element body ()

Accessor to the document's body element.

Returns
  • body

public Document clone ()

Create a stand-alone, deep copy of this node, and all of its children. The cloned node will have no siblings or parent node. As a stand-alone object, any changes made to the clone or any of its children will not impact the original node.

The cloned node may be adopted into another Document or node structure using appendChild(Node).

Returns
  • stand-alone cloned node

public Element createElement (String tagName)

Create a new Element, with this document's base uri. Does not make the new element a child of this document.

Parameters
tagName element tag name (e.g. a)
Returns
  • new element

public static Document createShell (String baseUri)

Create a valid, empty shell of a document, suitable for adding more elements to.

Parameters
baseUri baseUri of document
Returns
  • document with html, head, and body elements.

public Element head ()

Accessor to the document's head element.

Returns
  • head

public String nodeName ()

Get the node name of this node. Use for debugging purposes and not logic switching (for that, use instanceof).

Returns
  • node name

public Document normalise ()

Normalise the document. This happens after the parse phase so generally does not need to be called. Moves any text content that is not in the body element into the body.

Returns
  • this document after normalisation

public String outerHtml ()

Get the outer HTML of this node.

Returns
  • HTML

public Document.OutputSettings outputSettings ()

Get the document's current output settings.

Returns
  • the document's current output settings.

public Element text (String text)

Set the text of the body of this document. Any existing nodes within the body will be cleared.

Parameters
text unencoded text
Returns
  • this document

public String title ()

Get the string contents of the document's title element.

Returns
  • Trimed title, or empty string if none set.

public void title (String title)

Set the document's title element. Updates the existing element, or adds title to head if not present

Parameters
title string to set as title