Package org.jsoup.parser
Class XmlTreeBuilder
java.lang.Object
org.jsoup.parser.XmlTreeBuilder
Use the
XmlTreeBuilder when you want to parse XML without any of the HTML DOM rules being applied to the
document.
Usage example: Document xmlDoc = Jsoup.parse(html, baseUrl, Parser.xmlParser());
- Author:
- Jonathan Hedley
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ElementGet the current element (last on the stack).protected booleancurrentElementIs(String normalName) Checks if the Current Element's normal name equals the supplied name, in the HTML namespace.protected booleancurrentElementIs(String normalName, String namespace) Checks if the Current Element's normal name equals the supplied name, in the specified namespace.Gets the default namespace for this TreeBuilderprotected voidIf the parser is tracking errors, add an error at the current position.protected voidIf the parser is tracking errors, add an error at the current position.protected voidinitialiseParse(Reader input, String baseUri, Parser parser) protected voidinsertNode(Node node) protected voidinsertNode(Node node, org.jsoup.parser.Token token) protected booleanisContentForTagData(String normalName) (An internal method, visible for Element.protected voidonNodeClosed(Node node, org.jsoup.parser.Token token) Called by implementing TreeBuilders when a node is explicitly closed.protected voidonNodeInserted(Node node, org.jsoup.parser.Token token) Called by implementing TreeBuilders when a node has been inserted.protected voidpopStackToClose(org.jsoup.parser.Token.EndTag endTag) If the stack contains an element with this tag's name, pop up the stack to remove the first occurrence.protected booleanprocess(org.jsoup.parser.Token token) protected booleanprocessEndTag(String name) protected booleanprocessStartTag(String name) booleanprocessStartTag(String name, Attributes attrs) protected voidprotected TagtagFor(String tagName, String namespace, ParseSettings settings) protected TagtagFor(String tagName, ParseSettings settings)
-
Field Details
-
parser
-
doc
-
stack
-
baseUri
-
currentToken
protected org.jsoup.parser.Token currentToken -
settings
-
seenTags
-
-
Constructor Details
-
XmlTreeBuilder
public XmlTreeBuilder()
-
-
Method Details
-
initialiseParse
@ParametersAreNonnullByDefault protected void initialiseParse(Reader input, String baseUri, Parser parser) -
defaultNamespace
Gets the default namespace for this TreeBuilder- Returns:
- the default namespace
-
process
protected boolean process(org.jsoup.parser.Token token) -
insertNode
-
insertNode
-
popStackToClose
protected void popStackToClose(org.jsoup.parser.Token.EndTag endTag) If the stack contains an element with this tag's name, pop up the stack to remove the first occurrence. If not found, skips.- Parameters:
endTag- tag to close
-
runParser
protected void runParser() -
processStartTag
-
processStartTag
-
processEndTag
-
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
-
onNodeInserted
Called by implementing TreeBuilders when a node has been inserted. This implementation includes optionally tracking the source range of the node.- Parameters:
node- the node that was just insertedtoken- the (optional) token that created this node
-
onNodeClosed
Called by implementing TreeBuilders when a node is explicitly closed. This implementation includes optionally tracking the closing source range of the node.- Parameters:
node- the node being closedtoken- the end-tag token that closed this node
-