Package org.jsoup.parser
Class Tag
java.lang.Object
org.jsoup.parser.Tag
- All Implemented Interfaces:
-
Cloneable
public class Tag extends Object implements 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 int
Tag option: the tag is a block tag (e.g.static int
Tag option: the tag is a Data element that can have text but not character references (e.g.static int
Tag option: the tag's value will be included when submitting a form (e.g.static int
Tag option: the tag is a block tag that will only hold inline tags (e.g.static int
Tag option: the tag is known (specifically defined).static int
Tag option: the tag preserves whitespace (e.g.static int
Tag option: the tag is an RCDATA element that can have text and character references (e.g.static int
Tag option: the tag has been seen self-closing in this parse.static int
Tag option: the tag can self-close (e.g.static int
Tag option: the tag is a void tag (e.g. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclear
(int option) Clear (unset) an option from this tag.protected Tag
clone()
boolean
equals
(Object o) boolean
Deprecated.setting is only used within the Printer.String
getName()
Get this tag's name.int
hashCode()
boolean
is
(int option) Test if an option is set on this tag.boolean
isBlock()
Gets if this is a block tag.boolean
isEmpty()
Get if this is void (aka empty) tag.boolean
Deprecated.this method is internal to HtmlTreeBuilder only, and will be removed in 1.21.1.boolean
Get if this tag represents an element that should be submitted with a form.boolean
isInline()
Gets if this tag is an inline tag.boolean
Get if this is a pre-defined tag in the TagSet, or was auto created on parsing.static boolean
isKnownTag
(String tagName) Check if this tag name is a known HTML tag.boolean
Get if this tag is self-closing.String
Get this tag's local name.String
name()
Get this tag's name.name
(String tagName) Change the tag's name.String
Get this tag's namespace.namespace
(String namespace) Set the tag's namespace.String
Get this tag's normalized (lowercased) name.String
prefix()
Get this tag's prefix, if it has one; else the empty string.boolean
Get if this tag should preserve whitespace within child text nodes.set
(int option) Set an option on this tag.String
toString()
static Tag
valueOf
(String tagName) Get a Tag by name.static Tag
valueOf
(String tagName, String namespace, ParseSettings settings) Get a Tag by name.static Tag
valueOf
(String tagName, ParseSettings settings) Get a Tag by name.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
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: the tag is a block tag that will only hold inline tags (e.g.<p>
); used for formatting. (Must also set Block.) -
SelfClose
public static int SelfCloseTag option: the tag can self-close (e.g.). -
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>
).
-
-
Constructor Details
-
Tag
public Tag(String tagName, String namespace) 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
public Tag(String tagName) 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
public String getName()Get this tag's name.- Returns:
- the tag's name
-
name
public String 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
public String 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
public String 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
public String normalName()Get this tag's normalized (lowercased) name.- Returns:
- the tag's normal name.
-
namespace
public String 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 public boolean formatAsBlock()Deprecated.setting is only used within the Printer. Will be removed in 1.21.Get if this is an InlineContainer tag.- Returns:
- true if an InlineContainer (which formats children as inline).
-
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
public static boolean isKnownTag(String tagName) 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
-
isFormListed
@Deprecated public boolean isFormListed()Deprecated.this method is internal to HtmlTreeBuilder only, and will be removed in 1.21.1.Get if this tag represents a control associated with a form. E.g. input, textarea, output- Returns:
- if associated with a form
-
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
-
equals
public boolean equals(Object o) - Overrides:
-
equals
in classObject
-
hashCode
public int hashCode()- Overrides:
-
hashCode
in classObject
-
toString
public String toString()- Overrides:
-
toString
in classObject
-
clone
- Overrides:
-
clone
in classObject
-