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 | Class and Description |
---|---|
static interface |
TagNode.ITagNodeCondition
Used as base for different node checkers.
|
class |
TagNode.TagAllCondition
All nodes.
|
class |
TagNode.TagNodeAttExistsCondition
Checks if node contains specified attribute.
|
class |
TagNode.TagNodeAttValueCondition
Checks if node has specified attribute with specified value.
|
class |
TagNode.TagNodeNameCondition
Checks if node has specified name.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(String attName,
String attValue)
Deprecated.
Use setAttribute instead
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) |
TagNode[] |
getAllElements(boolean isRecursive) |
List |
getAllElementsList(boolean isRecursive) |
String |
getAttributeByName(String attName) |
Map<String,String> |
getAttributes() |
int |
getChildIndex(HtmlNode child) |
List |
getChildren() |
List |
getChildTagList() |
TagNode[] |
getChildTags() |
DoctypeToken |
getDocType() |
List |
getElementListByAttValue(String attName,
String attValue,
boolean isRecursive,
boolean isCaseSensitive) |
List |
getElementListByName(String findName,
boolean isRecursive) |
List |
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) |
Map<String,String> |
getNamespaceDeclarations() |
TagNode |
getParent() |
StringBuffer |
getText() |
boolean |
hasAttribute(String attName)
Checks existance 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
|
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 |
replaceChild(HtmlNode childToReplace,
HtmlNode replacement)
Replaces specified child node with specified replacement node.
|
void |
serialize(Serializer serializer,
Writer writer) |
void |
setAttribute(String attName,
String attValue)
Adding new attribute ir overriding existing one.
|
void |
setDocType(DoctypeToken docType) |
boolean |
setName(String name)
Changes name of the tag
|
void |
traverse(TagNodeVisitor visitor)
Traverses the tree and performs visitor's action on each node.
|
public TagNode(String name)
public boolean setName(String name)
name
- public String getAttributeByName(String attName)
attName
- public Map<String,String> getAttributes()
public boolean hasAttribute(String attName)
attName
- @Deprecated public void addAttribute(String attName, String attValue)
attName
- attValue
- public void setAttribute(String attName, String attValue)
attName
- attValue
- public void addNamespaceDeclaration(String nsPrefix, String nsURI)
nsPrefix
- Namespace prefixnsURI
- Namespace URIpublic Map<String,String> getNamespaceDeclarations()
public void removeAttribute(String attName)
attName
- public List getChildren()
public boolean hasChildren()
public List getChildTagList()
public TagNode[] getChildTags()
public StringBuffer getText()
public TagNode getParent()
public DoctypeToken getDocType()
public void setDocType(DoctypeToken docType)
public void addChild(Object child)
public void addChildren(List newChildren)
newChildren
- public List getAllElementsList(boolean isRecursive)
public TagNode[] getAllElements(boolean isRecursive)
public TagNode findElementHavingAttribute(String attName, boolean isRecursive)
public List 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 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 replaceChild(HtmlNode childToReplace, HtmlNode replacement)
childToReplace
- Child node to be replacedreplacement
- Replacement nodepublic 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 void traverse(TagNodeVisitor visitor)
visitor
- TagNodeVisitor implementationpublic void serialize(Serializer serializer, Writer writer) throws IOException
serialize
in interface BaseToken
IOException
Copyright © 2006–2017. All rights reserved.