Class TreeBuilder

java.lang.Object
org.jsoup.parser.TreeBuilder
Direct Known Subclasses:
HtmlTreeBuilder, XmlTreeBuilder

abstract class TreeBuilder extends Object
  • Field Details

  • Constructor Details

    • TreeBuilder

      TreeBuilder()
  • Method Details

    • defaultSettings

      abstract ParseSettings defaultSettings()
    • initialiseParse

      void initialiseParse(Reader input, String baseUri, Parser parser)
    • completeParse

      void completeParse()
    • parse

      Document parse(Reader input, String baseUri, Parser parser)
    • parseFragment

      List<Node> parseFragment(String inputFragment, Element context, String baseUri, Parser parser)
    • initialiseParseFragment

      void initialiseParseFragment(Element context)
    • completeParseFragment

      abstract List<Node> completeParseFragment()
    • nodeListener

      void nodeListener(NodeVisitor nodeListener)
      Set the node listener, which will then get callbacks for node insert and removals.
    • newInstance

      abstract TreeBuilder newInstance()
      Create a new copy of this TreeBuilder
      Returns:
      copy, ready for a new parse
    • runParser

      void runParser()
    • stepParser

      boolean stepParser()
    • process

      abstract boolean process(Token token)
    • processStartTag

      boolean processStartTag(String name)
    • processStartTag

      boolean processStartTag(String name, Attributes attrs)
    • processEndTag

      boolean processEndTag(String name)
    • pop

      final Element pop()
      Removes the last Element from the stack, hits onNodeClosed, and then returns it.
      Returns:
    • push

      final void push(Element element)
      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

      boolean currentElementIs(String normalName)
      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

      boolean currentElementIs(String normalName, String namespace)
      Checks if the Current Element's normal name equals the supplied name, in the specified namespace.
      Parameters:
      normalName - name to check
      namespace - the namespace
      Returns:
      true if there is a current element on the stack, and its name equals the supplied
    • error

      void error(String msg)
      If the parser is tracking errors, add an error at the current position.
      Parameters:
      msg - error message
    • error

      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

      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

      Tag tagFor(String tagName, String namespace, ParseSettings settings)
    • tagFor

      Tag tagFor(String tagName, ParseSettings settings)
    • defaultNamespace

      String defaultNamespace()
      Gets the default namespace for this TreeBuilder
      Returns:
      the default namespace
    • onNodeInserted

      void onNodeInserted(Node node)
      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

      void onNodeClosed(Node node)
      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

      private void trackNodePosition(Node node, boolean isStart)