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: the tag is a block tag that will only hold inline tags (e.g.,<p>); used for formatting.static intTag option: the tag is known (specifically defined).static 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 />).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
Constructors -
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.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
Tag 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
Tag option: the tag is a void tag (e.g.,<img>), that can contain no children, and in HTML does not require closing. -
Block
Tag 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
Tag option: the tag is a block tag that will only hold inline tags (e.g.,<p>); used for formatting. (Must also set Block.) -
SelfClose
Tag option: the tag can self-close (e.g.,<foo />). -
SeenSelfClose
Tag option: the tag has been seen self-closing in this parse. -
PreserveWhitespace
Tag option: the tag preserves whitespace (e.g.,<pre>). -
RcData
Tag option: the tag is an RCDATA element that can have text and character references (e.g.,<title>,<textarea>). -
Data
Tag option: the tag is a Data element that can have text but not character references (e.g.,<style>,<script>). -
FormSubmittable
Tag option: the tag's value will be included when submitting a form (e.g.,<input>).
-
-
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:
-
-
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
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
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 an InlineContainer (which formats children as inline).
-
isInline
Gets if this tag is an inline tag. Just the opposite of isBlock.- Returns:
- if this tag is an inline tag.
-
isEmpty
Get if this is void (aka empty) tag.- Returns:
- true if this is a void tag
-
isSelfClosing
Get if this tag is self-closing.- Returns:
- if this tag should be output as self-closing.
-
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
Get if this tag should preserve whitespace within child text nodes.- Returns:
- if preserve whitespace
-
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
-
equals
-
hashCode
Hashcode of this Tag, consisting of the tag name and namespace. -
toString
-
clone
-
isInline()orisBlock()to check layout intent.