org.htmlparser
public interface Node extends Cloneable
Method Summary | |
---|---|
void | accept(NodeVisitor visitor)
Apply the visitor to this node. |
Object | clone()
Allow cloning of nodes.
|
void | collectInto(NodeList list, NodeFilter filter)
Collect this node and its child nodes into a list, provided the node
satisfies the filtering criteria.
|
void | doSemanticAction()
Perform the meaning of this tag.
|
NodeList | getChildren()
Get the children of this node. |
int | getEndPosition()
Gets the ending position of the node.
|
Node | getFirstChild()
Get the first child of this node. |
Node | getLastChild()
Get the last child of this node. |
Node | getNextSibling()
Get the next sibling to this node. |
Page | getPage()
Get the page this node came from. |
Node | getParent()
Get the parent of this node.
|
Node | getPreviousSibling()
Get the previous sibling to this node. |
int | getStartPosition()
Gets the starting position of the node.
|
String | getText()
Returns the text of the node. |
void | setChildren(NodeList children)
Set the children of this node. |
void | setEndPosition(int position)
Sets the ending position of the node. |
void | setPage(Page page)
Set the page this node came from. |
void | setParent(Node node)
Sets the parent of this node. |
void | setStartPosition(int position)
Sets the starting position of the node. |
void | setText(String text)
Sets the string contents of the node. |
String | toHtml()
Return the HTML for this node.
|
String | toHtml(boolean verbatim)
Return the HTML for this node.
|
String | toPlainTextString()
A string representation of the node.
|
String | toString()
Return the string representation of the node.
|
Parameters: visitor The visitor to this node.
will be true, and that the expression:x.clone() != x
will be true, but these are not absolute requirements. While it is typically the case that:x.clone().getClass() == x.getClass()
will be true, this is not an absolute requirement.x.clone().equals(x)
By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().
By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.
The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object does not itself implement the interface Cloneable, so calling the clone method on an object whose class is Object will result in throwing an exception at run time.
Returns: a clone of this instance.
Throws: CloneNotSupportedException if the object's class does not
support the Cloneable
interface. Subclasses
that override the clone
method can also
throw this exception to indicate that an instance cannot
be cloned.
See Also: java.lang.Cloneable
This mechanism allows powerful filtering code to be written very easily, without bothering about collection of embedded tags separately. e.g. when we try to get all the links on a page, it is not possible to get it at the top-level, as many tags (like form tags), can contain links embedded in them. We could get the links out by checking if the current node is a CompositeTag, and going through its children. So this method provides a convenient way to do this.
Using collectInto(), programs get a lot shorter. Now, the code to extract all links from a page would look like:
NodeList list = new NodeList (); NodeFilter filter = new TagNameFilter ("A"); for (NodeIterator e = parser.elements (); e.hasMoreNodes ();) e.nextNode ().collectInto (list, filter);Thus,
list
will hold all the link nodes, irrespective of how
deep the links are embedded.
Another way to accomplish the same objective is:
NodeList list = new NodeList (); NodeFilter filter = new TagClassFilter (LinkTag.class); for (NodeIterator e = parser.elements (); e.hasMoreNodes ();) e.nextNode ().collectInto (list, filter);This is slightly less specific because the LinkTag class may be registered for more than one node name, e.g. <LINK> tags too.
Parameters: list The list to collect nodes into. filter The criteria to use when deciding if a node should be added to the list.
Throws: ParserException If a problem is encountered performing the semantic action.
Returns: The list of children contained by this node, if it's been set,
null
otherwise.
See Also: Node
Returns: The end position.
See Also: Node
Returns: The first child in the list of children contained by this node,
null
otherwise.
Returns: The last child in the list of children contained by this node,
null
otherwise.
Returns: The next sibling to this node if one exists,
null
otherwise.
Returns: The page that supplied this node.
See Also: Node
Returns: The parent of this node, if it's been set, null
otherwise.
See Also: Node
Returns: The previous sibling to this node if one exists,
null
otherwise.
Returns: The start position.
See Also: Node
Returns: The contents of the string or remark node, and in the case of a tag, the contents of the tag less the enclosing angle brackets.
See Also: Node
Parameters: children The new list of children this node contains.
See Also: Node
Parameters: position The new end position.
See Also: Node
Parameters: page The page that supplied this node.
See Also: Node
Parameters: node The node that contains this node.
See Also: Node
Parameters: position The new start position.
See Also: Node
Parameters: text The new text for the node.
See Also: Node
Returns: The sequence of characters that would cause this node to be returned by the parser or lexer.
Parameters: verbatim If true
return as close to the original
page text as possible.
Returns: The (exact) sequence of characters that would cause this node to be returned by the parser or lexer.
for (Enumeration e = parser.elements (); e.hasMoreElements ();) // or do whatever processing you wish with the plain text string System.out.println ((Node)e.nextElement ()).toPlainTextString ());
Returns: The text of this node including it's children.
System.out.println (node);or within a debugging environment.
Returns: A string representation of this node suitable for printing, that isn't too large.
HTML Parser is an open source library released under LGPL. | |