Menu

parsing multiple tags from one page

Help
2005-03-29
2013-04-27
  • Randy Paries

    Randy Paries - 2005-03-29

    Hello,
    Is there an example on how to parse multiple tags from one page?
    Currently i do a
    Parser parser = new Parser(filename);
    Node Nodes [] = parser.extractAllNodesThatAre(BodyTag.class);

    i also want to do
    Node NodesTitle [] = parser.extractAllNodesThatAre(TitleTag.class);

    Do i have to create a new parser?

    How is  the best way to do this

    Thanks

     
    • Derrick Oswald

      Derrick Oswald - 2005-03-29

      You can either reset() the parser and filter it all again, or use a dual purpose filter that accepts both types of nodes.

      If you look at the code behind extractAllNodesThatAre() it is using a NodeClassFilter:
          extractAllNodesThatMatch (new NodeClassFilter (<cls>));
      so you could get both types of nodes (assuming your program logic could handle it) with:
          extractAllNodesThatMatch (
              new OrFilter (
                  new NodeClassFilter (<cls1>),
                  new NodeClassFilter (<cls2>)));
      whichm because of the 'OR' permits both classes to pass.

       

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.