Package org.htmlparser.util
Class NodeList
java.lang.Object
org.htmlparser.util.NodeList
- All Implemented Interfaces:
Serializable
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
Add another node list to this one.asString()
boolean
Check to see if the NodeList contains the supplied Node.void
copyToNodeArray
(Node[] array) elementAt
(int i) elements()
extractAllNodesThatMatch
(NodeFilter filter) Filter the list with the given filter non-recursively.extractAllNodesThatMatch
(NodeFilter filter, boolean recursive) Filter the list with the given filter.int
Finds the index of the supplied Node.void
keepAllNodesThatMatch
(NodeFilter filter) Remove nodes not matching the given filter non-recursively.void
keepAllNodesThatMatch
(NodeFilter filter, boolean recursive) Remove nodes not matching the given filter.void
Insert the given node at the head of the list.remove
(int index) Remove the node at index.boolean
Remove the supplied Node from the list.void
int
size()
toHtml()
Convert this nodelist into the equivalent HTML.toHtml
(boolean verbatim) Convert this nodelist into the equivalent HTML.Node[]
toString()
Return the contents of the list as a string.void
visitAllNodesWith
(NodeVisitor visitor) Utility to apply a visitor to a node list.
-
Constructor Details
-
NodeList
public NodeList() -
NodeList
Create a one element node list.- Parameters:
node
- The initial node to add.
-
-
Method Details
-
add
-
add
Add another node list to this one.- Parameters:
list
- The list to add.
-
prepend
Insert the given node at the head of the list.- Parameters:
node
- The new first element.
-
size
public int size() -
elementAt
-
elements
-
toNodeArray
-
copyToNodeArray
-
asString
-
toHtml
Convert this nodelist into the equivalent HTML.- Parameters:
verbatim
- Iftrue
return as close to the original page text as possible.- Returns:
- The contents of the list as HTML text.
-
toHtml
Convert this nodelist into the equivalent HTML.- Returns:
- The contents of the list as HTML text.
-
remove
Remove the node at index.- Parameters:
index
- The index of the node to remove.- Returns:
- The node that was removed.
-
removeAll
public void removeAll() -
contains
Check to see if the NodeList contains the supplied Node.- Parameters:
node
- The node to look for.- Returns:
- True is the Node is in this NodeList.
-
indexOf
Finds the index of the supplied Node.- Parameters:
node
- The node to look for.- Returns:
- The index of the node in the list or -1 if it isn't found.
-
remove
Remove the supplied Node from the list.- Parameters:
node
- The node to remove.- Returns:
- True if the node was found and removed from the list.
-
toString
Return the contents of the list as a string. Suitable for debugging. -
extractAllNodesThatMatch
Filter the list with the given filter non-recursively.- Parameters:
filter
- The filter to use.- Returns:
- A new node array containing the nodes accepted by the filter. This is a linear list and preserves the nested structure of the returned nodes only.
-
extractAllNodesThatMatch
Filter the list with the given filter.- Parameters:
filter
- The filter to use.recursive
- Iftrue
digs into the children recursively.
- Returns:
- A new node array containing the nodes accepted by the filter. This is a linear list and preserves the nested structure of the returned nodes only.
-
keepAllNodesThatMatch
Remove nodes not matching the given filter non-recursively.- Parameters:
filter
- The filter to use.
-
keepAllNodesThatMatch
Remove nodes not matching the given filter.- Parameters:
filter
- The filter to use.recursive
- Iftrue
digs into the children recursively.
-
visitAllNodesWith
Utility to apply a visitor to a node list. Provides for a visitor to modify the contents of a page and get the modified HTML as a string with code like this:Parser parser = new Parser ("http://whatever"); NodeList list = parser.parse (null); // no filter list.visitAllNodesWith (visitor); System.out.println (list.toHtml ());
- Throws:
ParserException
-