Package org.jsoup.parser
Class TagSet
java.lang.Object
org.jsoup.parser.TagSet
public class TagSet extends Object
A TagSet controls the
Tag
configuration for a Document's parse, and its serialization. It contains the initial defaults, and after the parse, any additionally discovered tags.
- Since:
- 1.20.1
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionInsert a tag into this TagSet.boolean
equals
(Object o) @Nullable Tag
get
(String tagName, String namespace) Get an existing Tag from this TagSet by tagName and namespace.int
hashCode()
static TagSet
Html()
Returns a mutable copy of the default HTML tag set.Register a callback to customize eachTag
as it's added to this TagSet.valueOf
(String tagName, String namespace) Get a Tag by name from this TagSet.valueOf
(String tagName, String namespace, ParseSettings settings) Get a Tag by name from this TagSet.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Method Details
-
Html
Returns a mutable copy of the default HTML tag set. -
add
Insert a tag into this TagSet. If the tag already exists, it is replaced.Tags explicitly added like this are considered to be known tags (vs those that are dynamically created via .valueOf() if not already in the set.
- Parameters:
-
tag
- the tag to add - Returns:
- this TagSet
-
get
Get an existing Tag from this TagSet by tagName and namespace. The tag name is not normalized, to support mixed instances.- Parameters:
-
tagName
- the case-sensitive tag name -
namespace
- the namespace - Returns:
- the tag, or null if not found
-
valueOf
Get a Tag by name from this TagSet. If not previously defined (unknown), returns a new tag.New tags will be added to this TagSet.
- Parameters:
-
tagName
- Name of tag, e.g. "p". -
namespace
- the namespace for the tag. -
settings
- used to control tag name sensitivity - Returns:
- The tag, either defined or new generic.
-
valueOf
Get a Tag by name from this TagSet. If not previously defined (unknown), returns a new tag.New tags will be added to this TagSet.
- Parameters:
-
tagName
- Name of tag, e.g. "p". Case-sensitive. -
namespace
- the namespace for the tag. - Returns:
- The tag, either defined or new generic.
- See Also:
-
onNewTag
Register a callback to customize eachTag
as it's added to this TagSet.Customizers are invoked once per Tag, when they are added (explicitly or via the valueOf methods).
For example, to allow all unknown tags to be self-closing during when parsing as HTML:
Parser parser = Parser.htmlParser(); parser.tagSet().onNewTag(tag -> { if (!tag.isKnownTag()) tag.set(Tag.SelfClose); }); Document doc = Jsoup.parse(html, parser);
- Parameters:
-
customizer
- aConsumer<Tag>
that will be called for each newly added or cloned Tag; callers can inspect and modify the Tag's state (e.g. set options) - Returns:
- this TagSet, to allow method chaining
- Since:
- 1.21.0
-
equals
public boolean equals(Object o) - Overrides:
-
equals
in classObject
-
hashCode
public int hashCode()- Overrides:
-
hashCode
in classObject
-