Menu

issue when inserting tag using htmlparser

Help
likeBean
2006-07-27
2013-04-27
  • likeBean

    likeBean - 2006-07-27

    hi,I want the following html:
    <HTML><BODY><FORM ACTION='from.do'></FORM></BODY></HTML>
    become <HTML><BODY><TABLE ID='LJW'><FORM ACTION='from.do'></FORM></TABLE></BODY></HTML>

    following is my java code:

            String HTML_WITH_LINK =
                    "<HTML><BODY><FORM ACTION='from.do'></FORM></BODY></HTML>";
            Parser parser = Parser.createParser(HTML_WITH_LINK, null);
            NodeList list = parser.parse(null);
            FormTag formTag = (FormTag) list.extractAllNodesThatMatch(new
                    NodeClassFilter(FormTag.class), true).elementAt(0);
            TableTag table = new TableTag();
            table.setAttribute("id", "ljw");
            formTag.getParent().setChildren(new NodeList(table));
            table.setParent(formTag.getParent());
            table.setChildren(new NodeList(formTag));
            formTag.setParent(table);
            String result = list.toHtml(true);
            System.out.println(result);

    but the result print is :

    <HTML><BODY><TABLE id=ljw><FORM ACTION='from.do'></FORM></BODY></HTML>

    no </TABLE> end tag,how can i do?

    thanks

    Best rgds

     
    • Derrick Oswald

      Derrick Oswald - 2006-07-28

      I think a table.setEndTag (new Tag ("/TABLE")); should work.

       
    • likeBean

      likeBean - 2006-07-28

      thanks,but Tag is interface,can not be instanced,and I am confused that the end tag of the table tag is fixed,why need invoke setEndTag everyTime?

      Best Rgds

       
      • Derrick Oswald

        Derrick Oswald - 2006-07-29

        Sorry I should have said TagNode.
        End tags are only applicable to some tags, that's why they aren't automatically added.

         
    • likeBean

      likeBean - 2006-07-29

      Thanks ,I use:
      ...
      TagNode end = new TagNode();
      table.setEndTag(end);
      ...
      The issue resolved.

      But I still think auto added end tag is necessary when user create TableTag clearly.

      Best Rgds

       

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.