Package org.jsoup.parser
Class Tag
java.lang.Object
org.jsoup.parser.Tag
- All Implemented Interfaces:
Cloneable
A Tag represents an Element's name and configured options, common throughout the Document. Options may affect the parse
and output.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intTag option: the tag is a block tag (e.g.,<div>,<p>).static intTag option: the tag is a Data element that can have text but not character references (e.g.,<style>,<script>).static intTag option: the tag's value will be included when submitting a form (e.g.,<input>).static intTag option: pretty-print hint for block tags whose inline children should stay inline.static intTag option: the tag is known (specifically defined).(package private) String(package private) String(package private) intstatic intTag option: the tag preserves whitespace (e.g.,<pre>).static intTag option: the tag is an RCDATA element that can have text and character references (e.g.,<title>,<textarea>).static intTag option: the tag has been seen self-closing in this parse.static intTag option: the tag can self-close (e.g.,<foo />).(package private) Stringstatic intTag option: readable text boundary forElement.text(), used for controls, widgets, and embedded objects.static intTag option: the tag is a void tag (e.g.,<img>), that can contain no children, and in HTML does not require closing. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new Tag, with the given name, in the HTML namespace.Create a new Tag, with the given name and namespace.Path for TagSet defaults, no options set; normal name is already LC. -
Method Summary
Modifier and TypeMethodDescriptionclear(int option) Clear (unset) an option from this tag.protected Tagclone()booleanbooleanDeprecated.getName()Get this tag's name.inthashCode()Hashcode of this Tag, consisting of the tag name and namespace.booleanis(int option) Test if an option is set on this tag.booleanisBlock()Gets if this is a block tag.booleanisEmpty()Get if this is void (aka empty) tag.booleanGet if this tag represents an element that should be submitted with a form.booleanisInline()Gets if this tag is an inline tag.booleanGet if this is a pre-defined tag in the TagSet, or was auto created on parsing.static booleanisKnownTag(String tagName) Check if this tag name is a known HTML tag.booleanGet if this tag is self-closing.Get this tag's local name.name()Get this tag's name.Change the tag's name.Get this tag's namespace.Set the tag's namespace.Get this tag's normalized (lowercased) name.prefix()Get this tag's prefix, if it has one; else the empty string.booleanGet if this tag should preserve whitespace within child text nodes.set(int option) Set an option on this tag.(package private) void(package private) TokeniserStateIf this Tag uses a specific text TokeniserState for its content, returns that; otherwise null.toString()static TagGet a Tag by name.static TagvalueOf(String tagName, String namespace, ParseSettings settings) Get a Tag by name.static TagvalueOf(String tagName, ParseSettings settings) Get a Tag by name.
-
Field Details
-
Known
public static int KnownTag option: the tag is known (specifically defined). This impacts if options may need to be inferred (when not known) in, e.g., the pretty-printer. Set when a tag is added to a TagSet, or when settings are set(). -
Void
public static int VoidTag option: the tag is a void tag (e.g.,<img>), that can contain no children, and in HTML does not require closing. -
Block
public static int BlockTag option: the tag is a block tag (e.g.,<div>,<p>). Causes the element to be indented when pretty-printing. If not a block, it is inline. -
InlineContainer
public static int InlineContainerTag option: pretty-print hint for block tags whose inline children should stay inline. (Must also set Block.) -
SelfClose
public static int SelfCloseTag option: the tag can self-close (e.g.,<foo />). -
SeenSelfClose
public static int SeenSelfCloseTag option: the tag has been seen self-closing in this parse. -
PreserveWhitespace
public static int PreserveWhitespaceTag option: the tag preserves whitespace (e.g.,<pre>). -
RcData
public static int RcDataTag option: the tag is an RCDATA element that can have text and character references (e.g.,<title>,<textarea>). -
Data
public static int DataTag option: the tag is a Data element that can have text but not character references (e.g.,<style>,<script>). -
FormSubmittable
public static int FormSubmittableTag option: the tag's value will be included when submitting a form (e.g.,<input>). -
TextBoundary
public static int TextBoundaryTag option: readable text boundary forElement.text(), used for controls, widgets, and embedded objects. -
namespace
String namespace -
tagName
String tagName -
normalName
String normalName -
options
int options
-
-
Constructor Details
-
Tag
Create a new Tag, with the given name and namespace.The tag is not implicitly added to any TagSet.
- Parameters:
tagName- the name of the tag. Case-sensitive.namespace- the namespace for the tag.- Since:
- 1.20.1
- See Also:
-
Tag
Create a new Tag, with the given name, in the HTML namespace.The tag is not implicitly added to any TagSet.
- Parameters:
tagName- the name of the tag. Case-sensitive.- Since:
- 1.20.1
- See Also:
-
Tag
Path for TagSet defaults, no options set; normal name is already LC.
-
-
Method Details
-
getName
Get this tag's name.- Returns:
- the tag's name
-
name
Get this tag's name.- Returns:
- the tag's name
-
name
Change the tag's name. As Tags are reused throughout a Document, this will change the name for all uses of this tag.- Parameters:
tagName- the new name of the tag. Case-sensitive.- Returns:
- this tag
- Since:
- 1.20.1
-
prefix
Get this tag's prefix, if it has one; else the empty string.For example,
<book:title>has prefixbook, and tag namebook:title.- Returns:
- the tag's prefix
- Since:
- 1.20.1
-
localName
Get this tag's local name. The local name is the name without the prefix (if any).For exmaple,
<book:title>has local nametitle, and tag namebook:title.- Returns:
- the tag's local name
- Since:
- 1.20.1
-
normalName
Get this tag's normalized (lowercased) name.- Returns:
- the tag's normal name.
-
namespace
Get this tag's namespace.- Returns:
- the tag's namespace
-
namespace
Set the tag's namespace. As Tags are reused throughout a Document, this will change the namespace for all uses of this tag.- Parameters:
namespace- the new namespace of the tag.- Returns:
- this tag
- Since:
- 1.20.1
-
set
Set an option on this tag.Once a tag has a setting applied, it will be considered a known tag.
- Parameters:
option- the option to set- Returns:
- this tag
- Since:
- 1.20.1
-
is
public boolean is(int option) Test if an option is set on this tag.- Parameters:
option- the option to test- Returns:
- true if the option is set
- Since:
- 1.20.1
-
clear
Clear (unset) an option from this tag.- Parameters:
option- the option to clear- Returns:
- this tag
- Since:
- 1.20.1
-
valueOf
Get a Tag by name. If not previously defined (unknown), returns a new generic tag, that can do anything.Pre-defined tags (p, div etc) will be ==, but unknown tags are not registered and will only .equals().
- Parameters:
tagName- Name of tag, e.g. "p". Case-insensitive.namespace- the namespace for the tag.settings- used to control tag name sensitivity- Returns:
- The tag, either defined or new generic.
- See Also:
-
valueOf
Get a Tag by name. If not previously defined (unknown), returns a new generic tag, that can do anything.Pre-defined tags (P, DIV etc) will be ==, but unknown tags are not registered and will only .equals().
- Parameters:
tagName- Name of tag, e.g. "p". Case sensitive.- Returns:
- The tag, either defined or new generic.
- See Also:
-
valueOf
Get a Tag by name. If not previously defined (unknown), returns a new generic tag, that can do anything.Pre-defined tags (P, DIV etc) will be ==, but unknown tags are not registered and will only .equals().
- Parameters:
tagName- Name of tag, e.g. "p". Case sensitive.settings- used to control tag name sensitivity- Returns:
- The tag, either defined or new generic.
- See Also:
-
isBlock
public boolean isBlock()Gets if this is a block tag.- Returns:
- if block tag
-
formatAsBlock
Deprecated.internal pretty-printing flag; useisInline()orisBlock()to check layout intent. Will be removed in jsoup 1.24.1.Get if this is an InlineContainer tag.- Returns:
- true if this tag has the InlineContainer pretty-print hint.
-
isInline
public boolean isInline()Gets if this tag is an inline tag. Just the opposite of isBlock.- Returns:
- if this tag is an inline tag.
-
isEmpty
public boolean isEmpty()Get if this is void (aka empty) tag.- Returns:
- true if this is a void tag
-
isSelfClosing
public boolean isSelfClosing()Get if this tag is self-closing.- Returns:
- if this tag should be output as self-closing.
-
isKnownTag
public boolean isKnownTag()Get if this is a pre-defined tag in the TagSet, or was auto created on parsing.- Returns:
- if a known tag
-
isKnownTag
Check if this tag name is a known HTML tag.- Parameters:
tagName- name of tag- Returns:
- if known HTML tag
-
preserveWhitespace
public boolean preserveWhitespace()Get if this tag should preserve whitespace within child text nodes.- Returns:
- if preserve whitespace
-
isFormSubmittable
public boolean isFormSubmittable()Get if this tag represents an element that should be submitted with a form. E.g. input, option- Returns:
- if submittable with a form
-
setSeenSelfClose
void setSeenSelfClose() -
textState
TokeniserState textState()If this Tag uses a specific text TokeniserState for its content, returns that; otherwise null. -
equals
-
hashCode
public int hashCode()Hashcode of this Tag, consisting of the tag name and namespace. -
toString
-
clone
-
isInline()orisBlock()to check layout intent.