public class TagNode extends TagToken implements HtmlNode
XML node tag - basic node of the cleaned HTML tree. At the same time, it represents start tag token after HTML parsing phase and before cleaning phase. After cleaning process, tree structure remains containing tag nodes (TagNode class), content (text nodes - ContentNode), comments (CommentNode) and optionally doctype node (DoctypeToken).
Modifier and Type | Method | Description |
---|---|---|
void |
addAttribute(String attName,
String attValue) |
Adds specified attribute to this tag or overrides existing one.
|
void |
addChild(Object child) |
|
void |
addChildren(List newChildren) |
Add all elements from specified list to this node.
|
void |
addNamespaceDeclaration(String nsPrefix,
String nsURI) |
Adds namespace declaration to the node
|
Object[] |
evaluateXPath(String xPathExpression) |
Evaluates XPath expression on give node.
|
TagNode |
findElementByAttValue(String attName,
String attValue,
boolean isRecursive,
boolean isCaseSensitive) |
|
TagNode |
findElementByName(String findName,
boolean isRecursive) |
|
TagNode |
findElementHavingAttribute(String attName,
boolean isRecursive) |
|
List<? extends BaseToken> |
getAllChildren() |
|
TagNode[] |
getAllElements(boolean isRecursive) |
|
List<? extends TagNode> |
getAllElementsList(boolean isRecursive) |
|
String |
getAttributeByName(String attName) |
|
Map<String,String> |
getAttributes() |
Returns the attributes of the tagnode.
|
Map<String,String> |
getAttributesInLowerCase() |
Returns the attributes of the tagnode in lower case.
|
int |
getChildIndex(HtmlNode child) |
|
List<TagNode> |
getChildren() |
Deprecated.
use
getChildTagList() , will be refactored and possibly removed in
future versions. |
List<TagNode> |
getChildTagList() |
|
TagNode[] |
getChildTags() |
|
DoctypeToken |
getDocType() |
|
List<? extends TagNode> |
getElementList(ITagNodeCondition condition,
boolean isRecursive) |
Get all elements in the tree that satisfy specified condition.
|
List<? extends TagNode> |
getElementListByAttValue(String attName,
String attValue,
boolean isRecursive,
boolean isCaseSensitive) |
|
List<? extends TagNode> |
getElementListByName(String findName,
boolean isRecursive) |
|
List<? extends TagNode> |
getElementListHavingAttribute(String attName,
boolean isRecursive) |
|
TagNode[] |
getElementsByAttValue(String attName,
String attValue,
boolean isRecursive,
boolean isCaseSensitive) |
|
TagNode[] |
getElementsByName(String findName,
boolean isRecursive) |
|
TagNode[] |
getElementsHavingAttribute(String attName,
boolean isRecursive) |
|
String |
getName() |
|
Map<String,String> |
getNamespaceDeclarations() |
|
TagNode |
getParent() |
|
CharSequence |
getText() |
|
boolean |
hasAttribute(String attName) |
Checks existence of specified attribute.
|
boolean |
hasChildren() |
|
void |
insertChild(int index,
HtmlNode childToAdd) |
Inserts specified node at specified position in array of children
|
void |
insertChildAfter(HtmlNode node,
HtmlNode nodeToInsert) |
Inserts specified node in the list of children after specified child
|
void |
insertChildBefore(HtmlNode node,
HtmlNode nodeToInsert) |
Inserts specified node in the list of children before specified child
|
boolean |
isAutoGenerated() |
|
boolean |
isCopy() |
|
boolean |
isEmpty() |
|
boolean |
isForeignMarkup() |
|
boolean |
isPruned() |
|
boolean |
isTrimAttributeValues() |
|
TagNode |
makeCopy() |
|
void |
removeAllChildren() |
Removes all children (subelements and text content).
|
void |
removeAttribute(String attName) |
Removes specified attribute from this tag.
|
boolean |
removeChild(Object child) |
Remove specified child element from this node.
|
boolean |
removeFromTree() |
Remove this node from the tree.
|
void |
serialize(Serializer serializer,
Writer writer) |
|
void |
setAttributes(Map<String,String> attributes) |
Replace the current set of attributes with a new set.
|
void |
setAutoGenerated(boolean autoGenerated) |
|
void |
setChildren(List<? extends BaseToken> children) |
|
void |
setDocType(DoctypeToken docType) |
|
void |
setForeignMarkup(boolean isForeignMarkup) |
|
void |
setPruned(boolean pruned) |
|
void |
setTrimAttributeValues(boolean isTrimAttributeValues) |
|
void |
traverse(TagNodeVisitor visitor) |
Traverses the tree and performs visitor's action on each node.
|
getCol, getRow, setCol, setRow
public TagNode(String name)
public String getAttributeByName(String attName)
attName
- public Map<String,String> getAttributes()
public Map<String,String> getAttributesInLowerCase()
public void setAttributes(Map<String,String> attributes)
attributes
- public boolean hasAttribute(String attName)
attName
- public void addAttribute(String attName, String attValue)
attName
- attValue
- public void removeAttribute(String attName)
attName
- @Deprecated public List<TagNode> getChildren()
getChildTagList()
, will be refactored and possibly removed in
future versions. TODO This method should be refactored because is does not
properly match the commonly used Java's getter/setter strategy.public boolean hasChildren()
public TagNode[] getChildTags()
public CharSequence getText()
public int getChildIndex(HtmlNode child)
child
- Child to find index ofpublic void insertChild(int index, HtmlNode childToAdd)
index
- childToAdd
- public void insertChildBefore(HtmlNode node, HtmlNode nodeToInsert)
node
- Child before which to insert new nodenodeToInsert
- Node to be inserted at specified positionpublic void insertChildAfter(HtmlNode node, HtmlNode nodeToInsert)
node
- Child after which to insert new nodenodeToInsert
- Node to be inserted at specified positionpublic TagNode getParent()
public DoctypeToken getDocType()
public void setDocType(DoctypeToken docType)
public void addChild(Object child)
public void addChildren(List newChildren)
newChildren
- public List<? extends TagNode> getElementList(ITagNodeCondition condition, boolean isRecursive)
condition
- isRecursive
- public TagNode[] getAllElements(boolean isRecursive)
public List<? extends TagNode> getElementListByName(String findName, boolean isRecursive)
public TagNode findElementHavingAttribute(String attName, boolean isRecursive)
public List<? extends TagNode> getElementListHavingAttribute(String attName, boolean isRecursive)
public TagNode[] getElementsHavingAttribute(String attName, boolean isRecursive)
public TagNode findElementByAttValue(String attName, String attValue, boolean isRecursive, boolean isCaseSensitive)
public List<? extends TagNode> getElementListByAttValue(String attName, String attValue, boolean isRecursive, boolean isCaseSensitive)
public TagNode[] getElementsByAttValue(String attName, String attValue, boolean isRecursive, boolean isCaseSensitive)
public Object[] evaluateXPath(String xPathExpression) throws XPatherException
- //div//a
- //div//a[@id][@class]
- /body/*[1]/@type
- //div[3]//a[@id][@href='r/n4']
- //div[last() >= 4]//./div[position() = last()])[position() > 22]//li[2]//a
- //div[2]/@*[2]
- data(//div//a[@id][@class])
- //p/last()
- //body//div[3][@class]//span[12.2
- data(//a['v' < @id])
xPathExpression
- XPatherException
public boolean removeFromTree()
public boolean removeChild(Object child)
child
- public void removeAllChildren()
public void setAutoGenerated(boolean autoGenerated)
autoGenerated
- the autoGenerated to setpublic boolean isAutoGenerated()
public boolean isPruned()
public void setPruned(boolean pruned)
public boolean isEmpty()
public void addNamespaceDeclaration(String nsPrefix, String nsURI)
nsPrefix
- Namespace prefixnsURI
- Namespace URIpublic Map<String,String> getNamespaceDeclarations()
public void serialize(Serializer serializer, Writer writer) throws IOException
serialize
in interface BaseToken
IOException
public TagNode makeCopy()
public boolean isCopy()
public void traverse(TagNodeVisitor visitor)
visitor
- TagNodeVisitor implementationpublic boolean isForeignMarkup()
public void setForeignMarkup(boolean isForeignMarkup)
isForeignMarkup
- the isForeignMarkup to setpublic boolean isTrimAttributeValues()
public void setTrimAttributeValues(boolean isTrimAttributeValues)
isTrimAttributeValues
- the isTrimAttributeValues to setCopyright © 2006–2018. All rights reserved.