Replacing or deleting content of html file

Vinoth K G
2004-06-02
2004-06-03
  • Vinoth K G

    Vinoth K G - 2004-06-02

    Is it is possible to delete and replace the content of html file using the HTML parser. If possible using which class. How?

     
    • Derrick Oswald

      Derrick Oswald - 2004-06-03

      The HTML Parser doesn't really handle the synthesis use-case very well (see http://htmlparser.sourceforge.net/\), but here goes.

      Let's say all your page is a set of two nodes, the <HEAD></HEAD> node and the <BODY></BODY> node, which you got from your NodeIterator and put into a NodeList as element zero and element one.

      To remove all the body, use:
          Tag body = nodelist.elementAt (1);
          body.removeAll ();
      To add a string like
        hello world
      where world is bolded, use:
          body.add (new StringNode ("hello "));
          Tag b = new Tag ();
          b.setTagName ("B"); // bold
          body.add (b);
          body.add (new StringNode ("world");
          Tag no_b = new Tag ();
          no_b.setTagName ("/B"); // not bold
          body.add (no_b);

      Like I said, it's not really good at it.

       
    • Derrick Oswald

      Derrick Oswald - 2004-06-03

      Sorry,
      the line
           Tag body = nodelist.elementAt (1);
      should be
           NodeList body = nodelist.elementAt (1).getChildren ();
      so all the operations are on the children of the <BODY></BODY> node.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks