Package org.jsoup.parser

# Class XmlTreeBuilder

java.lang.Object
org.jsoup.parser.XmlTreeBuilder

public class XmlTreeBuilder extends Object
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
Modifier and Type
Field
Description
`protected String`
`baseUri`
`protected org.jsoup.parser.Token`
`currentToken`
`protected Document`
`doc`
`protected Parser`
`parser`
`protected Map<String,Tag>`
`seenTags`
`protected ParseSettings`
`settings`
`protected ArrayList<Element>`
`stack`

## Constructor Summary

Constructors
Constructor
Description
`XmlTreeBuilder()`

## Method Summary

Modifier and Type
Method
Description
`protected Element`
`currentElement()`
Get the current element (last on the stack).
`protected boolean`
`currentElementIs(String normalName)`
Checks if the Current Element's normal name equals the supplied name.
`protected void`
`error(String msg)`
If the parser is tracking errors, add an error at the current position.
`protected void`
`error(String msg, Object... args)`
If the parser is tracking errors, add an error at the current position.
`protected void`
`initialiseParse(Reader input, String baseUri, Parser parser)`
`protected void`
`insertNode(Node node)`
`protected void`
`insertNode(Node node, org.jsoup.parser.Token token)`
`protected boolean`
`isContentForTagData(String normalName)`
(An internal method, visible for Element.
`protected void`
`onNodeClosed(Node node, org.jsoup.parser.Token token)`
Called by implementing TreeBuilders when a node is explicitly closed.
`protected void`
`onNodeInserted(Node node, org.jsoup.parser.Token token)`
Called by implementing TreeBuilders when a node has been inserted.
`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.
`protected boolean`
`process(org.jsoup.parser.Token token)`
`protected boolean`
`processEndTag(String name)`
`protected boolean`
`processStartTag(String name)`
`boolean`
`processStartTag(String name, Attributes attrs)`
`protected void`
`runParser()`
`protected Tag`
`tagFor(String tagName, ParseSettings settings)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### parser

protected Parser parser

### doc

protected Document doc

### stack

protected ArrayList<Element> stack

### baseUri

protected String baseUri

### currentToken

protected org.jsoup.parser.Token currentToken

### settings

protected ParseSettings settings

### seenTags

protected Map<String,Tag> seenTags

## Constructor Details

### XmlTreeBuilder

public XmlTreeBuilder()

## Method Details

### initialiseParse

@ParametersAreNonnullByDefault protected void initialiseParse(Reader input, String baseUri, Parser parser)

### process

protected boolean process(org.jsoup.parser.Token token)

### insertNode

protected void insertNode(Node node)

### insertNode

protected void insertNode(Node node, org.jsoup.parser.Token token)

### 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

protected boolean processStartTag(String name)

### processStartTag

public boolean processStartTag(String name, Attributes attrs)

### processEndTag

protected boolean processEndTag(String name)

### currentElement

protected 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

protected boolean currentElementIs(String normalName)
Checks if the Current Element's normal name equals the supplied name.

Parameters:
  `normalName` - name to check
Returns:
  true if there is a current element on the stack, and its name equals the supplied

### error

protected void error(String msg)
If the parser is tracking errors, add an error at the current position.

Parameters:
  `msg` - error message

### error

protected void error(String msg, Object... args)
If the parser is tracking errors, add an error at the current position.

Parameters:
  `msg` - error message template
  `args` - template arguments

### isContentForTagData

protected boolean isContentForTagData(String normalName)
(An internal method, visible for Element. For HTML parse, signals that script and style text should be treated as Data Nodes).

### tagFor

protected Tag tagFor(String tagName, ParseSettings settings)

### onNodeInserted

protected void onNodeInserted(Node node, @Nullable org.jsoup.parser.Token token)
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 inserted
  `token` - the (optional) token that created this node

### onNodeClosed

protected void onNodeClosed(Node node, org.jsoup.parser.Token token)
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 closed
  `token` - the end-tag token that closed this node