Menu

Can i parse, update and then body.toHtml()??

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

    Randy Paries - 2005-03-29

    Hello,
    I have a html file
    I parse the html, then i want to update some info between the tags, then write out everything back to a file.
    Is this possible??

    thanks
    Randy

     
    • Derrick Oswald

      Derrick Oswald - 2005-03-29

      Basically yes.

      Recent additions (the last couple of integration builds) have added methods to collect all top level nodes into a NodeList, and then print lists out with toHtml(). So if you use visitors or filters:

      NodeList list = parser.parse (null); // no filter gets everything
      list.visitAllNodesWith (visitor); // process nodes here
      // or NodeList subset = list.extractAllNodesThatMatch (filter);
      //     ... process the subset here (they're still in list)
      System.out.println (list.toHtml ());

       
    • Randy Paries

      Randy Paries - 2005-03-31

      Hello,
      I must be missing something
      if i do the following the page gets outputed
      Parser parser = new Parser("C:\\UnitNet\\UnitNetServlet\\webapp\\paries\\mainUgly.html");
      NodeList nl = parser.parse(null);
      System.out.println( nl.toHtml() );

      but then if i try( factory stuff deleted but tags we added ), unWelcomeList   comes back with a size of zero.....
                      NodeList unWelcomeList  = nl.extractAllNodesThatMatch (
                                                      new OrFilter ( new NodeClassFilter (UnitNetWelcomeTag.class),
                                                                     new NodeClassFilter (UnitNetUpdateTag.class)
                                                                    )
                                               );

      but, if i leave out the  NodeList nl = parser.parse(null); and change nl.extractAllNodesThatMatch
      to parser.extractAllNodesThatMatch i get the stuff expected. Boy i hope this makes sense.

      Randy

       
      • Derrick Oswald

        Derrick Oswald - 2005-04-01

        No, it doesn't make a lot of sense. Sorry.

        Maybe this will help...
        When are you registering your custom tags?
        You need to register these before parsing, either with parser.parse() or parser.extractAllNodesThatMatch.
        The custom nodes are only formed when the page is parsed.
        After the nodes are in a NodeList it's too late.

         

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.