The filter operation extractAllNodesThatMatch() already visits every node with the filter, so they are almost identical in operation.
The visitor pattern uses accept() calls, while the filter pattern uses collectInto(), which if you examine the composit tag class do very nearly the same thing.
What are you trying to do that needs to combine two traversals of the node tree?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My Browser is "nokia browser" which cannot identify "Script" tag.
So I have to
(1)filter out "Script" tag and attributes of "Script" tag.
(2)filter out string which contain the string "Script".
then I have to visit all tags,make changes to tags' name and tags'
attributes.
recently,I find the following pattern is good.
Is it possible to translate a HTML file into a XHTML file
by the following pattern ?...@@.
--------------------------------------------------
Suggested Design
--------------------------------------------------
Parser parser = new Parser("http://www.yahoo.com");
NodeFilter filter=new NotFilter(new TagNameFilter("Script"));
parser.parse(filter);
for (NodeIterator i = parser.elements();i.hasMoreElements();) {
Node node = i.nextHTMLNode();
if (node instanceof StringNode) {
// Downcasting to StringNode
StringNode stringNode = (StringNode)node;
// Do whatever processing you want with the string node
System.out.println(stringNode.getText());
}
// Check for the node or tag that you want
if (node instanceof ...) {
// Downcast, and process
// recursively (nodes within nodes)
}
}
--------------------------------------------------
thank you
May goodness be with you all
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
regards:
How to combine Filter and Visitor pattern?....@@.
could some give me a short example?...@@
could some give me a hand?...@@.
Any example is welcome.
thank you
May goodness be with you all
The filter operation extractAllNodesThatMatch() already visits every node with the filter, so they are almost identical in operation.
The visitor pattern uses accept() calls, while the filter pattern uses collectInto(), which if you examine the composit tag class do very nearly the same thing.
What are you trying to do that needs to combine two traversals of the node tree?
regards:
thank you for reply.I'll check again.
thank you
May goodness be with you all
regards:
I plan to use htmlparser 1.5 translate
a HTML file into a XHTML file.
My goal is as the link:
http://www.wretch.cc/album/show.php?i=otp&b=1&f=1107098054&p=0
sorry now cannot connect to it. =.=
My Browser is "nokia browser" which cannot identify "Script" tag.
So I have to
(1)filter out "Script" tag and attributes of "Script" tag.
(2)filter out string which contain the string "Script".
then I have to visit all tags,make changes to tags' name and tags'
attributes.
recently,I find the following pattern is good.
Is it possible to translate a HTML file into a XHTML file
by the following pattern ?...@@.
--------------------------------------------------
Suggested Design
--------------------------------------------------
Parser parser = new Parser("http://www.yahoo.com");
NodeFilter filter=new NotFilter(new TagNameFilter("Script"));
parser.parse(filter);
for (NodeIterator i = parser.elements();i.hasMoreElements();) {
Node node = i.nextHTMLNode();
if (node instanceof StringNode) {
// Downcasting to StringNode
StringNode stringNode = (StringNode)node;
// Do whatever processing you want with the string node
System.out.println(stringNode.getText());
}
// Check for the node or tag that you want
if (node instanceof ...) {
// Downcast, and process
// recursively (nodes within nodes)
}
}
--------------------------------------------------
thank you
May goodness be with you all