Take the following HTML segment as an example:
<p>This is a sample paragraph.</p>
The whole segment is represented by an Element
object. This is comprised of the {@link StartTag} "<p>
",the {@link EndTag} "</p>
", as well as the text in between.An element may also contain other elements between its start and end tags.
The term normal element refers to an element having a {@linkplain #getStartTag() start tag}with a {@linkplain StartTag#getStartTagType() type} of {@link StartTagType#NORMAL}. This comprises all {@linkplain HTMLElements HTML elements} and non-HTML elements.
Element
instances are obtained using one of the following methods:
The three possible structures of an element are listed below:
<img src="mypicture.jpg">
The element consists only of a single {@linkplain #getStartTag() start tag} and has no {@linkplain #getContent() element content}(although the start tag itself may have {@linkplain StartTag#getTagContent() tag content}).
{@link #getEndTag()}==null
{@link #isEmpty()}==true
{@link #getEnd() getEnd()}==
{@link #getStartTag()}.
{@link #getEnd() getEnd()}
This occurs in the following situations:
<p>This is a sample paragraph.</p>
The element consists of a {@linkplain #getStartTag() start tag}, {@linkplain #getContent() content}, and an {@linkplain #getEndTag() end tag}.
{@link #getEndTag()}!=null
.
{@link #isEmpty()}==false
(provided the end tag doesn't immediately follow the start tag)
{@link #getEnd() getEnd()}==
{@link #getEndTag()}.
{@link #getEnd() getEnd()}.
This occurs in the following situations, assuming the start tag's matching end tag is present in the source document:
<p>This text is included in the paragraph element even though no end tag is present.
<p>This is the next paragraph.
The element consists of a {@linkplain #getStartTag() start tag} and {@linkplain #getContent() content}, but no {@linkplain #getEndTag() end tag}.
{@link #getEndTag()}==null
.
{@link #isEmpty()}==false
{@link #getEnd() getEnd()}!=
{@link #getStartTag()}.
{@link #getEnd() getEnd()}.
This only occurs in an HTML element for which the {@linkplain HTMLElements#getEndTagOptionalElementNames() end tag is optional}.
The element ends at the start of a tag which implies the termination of the element, called the implicitly terminating tag. If the implicitly terminating tag is situated immediately after the element's {@linkplain #getStartTag() start tag}, the element is classed as a single tag element.
See the element parsing rules for HTML elements with optional end tags for details on which tags can implicitly terminate a given element.
See also the documentation of the {@link HTMLElements#getEndTagOptionalElementNames()} method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|