Package org.jsoup.parser
Class TreeBuilder
java.lang.Object
org.jsoup.parser.TreeBuilder
- Direct Known Subclasses:
HtmlTreeBuilder
,XmlTreeBuilder
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) String
(package private) Token
(package private) Document
private final Token.EndTag
protected Parser
(package private) CharacterReader
(package private) ParseSettings
private Token.StartTag
(package private) Tokeniser
(package private) boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) Element
Get the current element (last on the stack).(package private) boolean
currentElementIs
(String normalName) Checks if the Current Element's normal name equals the supplied name, in the HTML namespace.(package private) boolean
currentElementIs
(String normalName, String namespace) Checks if the Current Element's normal name equals the supplied name, in the specified namespace.(package private) String
Gets the default namespace for this TreeBuilder(package private) abstract ParseSettings
(package private) void
If the parser is tracking errors, add an error at the current position.(package private) void
If the parser is tracking errors, add an error at the current position.(package private) void
initialiseParse
(Reader input, String baseUri, Parser parser) (package private) boolean
isContentForTagData
(String normalName) (An internal method, visible for Element.(package private) abstract TreeBuilder
Create a new copy of this TreeBuilder(package private) void
onNodeClosed
(Node node) Called by implementing TreeBuilders when a node is explicitly closed.(package private) void
onNodeInserted
(Node node) Called by implementing TreeBuilders when a node has been inserted.(package private) Document
parseFragment
(String inputFragment, Element context, String baseUri, Parser parser) (package private) final Element
pop()
Removes the last Element from the stack, hits onNodeClosed, and then returns it.(package private) abstract boolean
(package private) boolean
processEndTag
(String name) (package private) boolean
processStartTag
(String name) (package private) boolean
processStartTag
(String name, Attributes attrs) (package private) final void
Adds the specified Element to the end of the stack, and hits onNodeInserted.(package private) void
(package private) Tag
tagFor
(String tagName, String namespace, ParseSettings settings) (package private) Tag
tagFor
(String tagName, ParseSettings settings) private void
trackNodePosition
(Node node, boolean isStart)
-
Field Details
-
parser
-
reader
CharacterReader reader -
tokeniser
Tokeniser tokeniser -
doc
Document doc -
stack
-
baseUri
String baseUri -
currentToken
Token currentToken -
settings
ParseSettings settings -
seenTags
-
start
-
end
-
trackSourceRange
boolean trackSourceRange
-
-
Constructor Details
-
TreeBuilder
TreeBuilder()
-
-
Method Details
-
defaultSettings
-
initialiseParse
-
parse
-
newInstance
Create a new copy of this TreeBuilder- Returns:
- copy, ready for a new parse
-
parseFragment
-
runParser
void runParser() -
process
-
processStartTag
-
processStartTag
-
processEndTag
-
pop
Removes the last Element from the stack, hits onNodeClosed, and then returns it.- Returns:
-
push
Adds the specified Element to the end of the stack, and hits onNodeInserted.- Parameters:
element
-
-
currentElement
Element currentElement()Get the current element (last on the stack). If all items have been removed, returns the document instead (which might not actually be on the stack; use stack.size() == 0 to test if required.- Returns:
- the last element on the stack, if any; or the root document
-
currentElementIs
Checks if the Current Element's normal name equals the supplied name, in the HTML namespace.- Parameters:
normalName
- name to check- Returns:
- true if there is a current element on the stack, and its name equals the supplied
-
currentElementIs
Checks if the Current Element's normal name equals the supplied name, in the specified namespace.- Parameters:
normalName
- name to checknamespace
- the namespace- Returns:
- true if there is a current element on the stack, and its name equals the supplied
-
error
If the parser is tracking errors, add an error at the current position.- Parameters:
msg
- error message
-
error
If the parser is tracking errors, add an error at the current position.- Parameters:
msg
- error message templateargs
- template arguments
-
isContentForTagData
(An internal method, visible for Element. For HTML parse, signals that script and style text should be treated as Data Nodes). -
tagFor
-
tagFor
-
defaultNamespace
String defaultNamespace()Gets the default namespace for this TreeBuilder- Returns:
- the default namespace
-
onNodeInserted
Called by implementing TreeBuilders when a node has been inserted. This implementation includes optionally tracking the source range of the node. @param node the node that was just inserted -
onNodeClosed
Called by implementing TreeBuilders when a node is explicitly closed. This implementation includes optionally tracking the closing source range of the node. @param node the node being closed -
trackNodePosition
-