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 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()booleanequals(Object o) booleanDeprecated.setting is only used within the Printer.StringgetName()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.StringGet this tag's local name.Stringname()Get this tag's name.name(String tagName) Change the tag's name.StringGet this tag's namespace.namespace(String namespace) Set the tag's namespace.StringGet this tag's normalized (lowercased) name.Stringprefix()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.StringtoString()static TagvalueOf(String tagName) Get 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.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.,<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>).
-
-
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 a future release.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
-
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:
-
equalsin classObject
-
hashCode
public int hashCode()Hashcode of this Tag, consisting of the tag name and namespace.- Overrides:
-
hashCodein classObject
-
toString
public String toString()- Overrides:
-
toStringin classObject
-
clone
- Overrides:
-
clonein classObject
-