Menu

How to combine Filter and Visitor pattern?...

Help
2005-02-04
2013-04-27
  • mikeliu1976

    mikeliu1976 - 2005-02-04

    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

     
    • Derrick Oswald

      Derrick Oswald - 2005-02-05

      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?

       
    • mikeliu1976

      mikeliu1976 - 2005-02-06

      regards:

      thank you for reply.I'll check again.

      thank you
      May goodness be with you all

       
    • mikeliu1976

      mikeliu1976 - 2005-02-06

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.