Menu

how to solve this

Help
sidhu
2005-09-14
2013-04-27
  • sidhu

    sidhu - 2005-09-14

    anyone help plz
    i have a HTML file looks like this

    <html>

    <body>

    <h1> My First Page

        <table> 
        Student Detail
       
           <tr height="15"> Translation
                <td> David </td>
                <td> John </td>
          
           <tr> 217.47
                <td> Vasu </td>
                <td> ali </td>
          
           <tr height="12">
                <td> Our </td>
                <td> Concern </td>
           </tr>       
               
       
       
       

    </html>
    the output comes after cleaning malformed page is like

    <html>

    <body>

    <h1> My First Page

        <table>
        Student Detail

           <tr height="15"> Translation
                <td> David </td>
                <td> John </td>

           </tr><tr> 217.47
                <td> Vasu </td>
                <td> ali </td>

           </tr><tr height="12">
                <td> Our </td>
                <td> Concern </td>
           </tr>

    </table></h1></body>
    </html>

    while the correct output will be

    <html>

    <body>

    <h1> My First Page </h1>

        <table>
        Student Detail

           <tr height="15"> Translation
                <td> David </td>
                <td> John </td>
           </tr>
           <tr> 217.47
                <td> Vasu </td>
                <td> ali </td>
           </tr>
           <tr height="12">
                <td> Our </td>
                <td> Concern </td>
           </tr>

        </table>

    </body>

    </html>

    can someone help how to rectify  the <h1> tag so that correct page get's displyed up
    the code i have used is
    public class ToHtmlDemo
    {
        public static void main (String[] args) throws ParserException
        {
            Parser parser = new Parser (args[0]);
            StringBuffer html = new StringBuffer (4096);
            PrototypicalNodeFactory factory = new PrototypicalNodeFactory ();
             factory.registerTag (new MyTagH1 ());
               
                 parser.setNodeFactory (factory);

            for (NodeIterator i = parser.elements();i.hasMoreNodes();)
                 html.append (i.nextNode().toHtml ());
            System.out.println (html);
    /*        for (Enumeration e = parser.elements (); e.hasMoreElements ();)
         System.out.println (((Node)e.nextElement ()).toPlainTextString ());
    */
        }
    }

    for h1 tag

    public class MyTagH1 extends CompositeTag
    {
    public static StringBuffer mBuffer = new StringBuffer ();

    /**
    * The set of names handled by this tag.
    */
    private static final String[] mIds = new String[] {"H1"};

    /**
    * Create a new text tag.
    */
    public MyTagH1 ()
    {
        //setThisScanner (mDefaultCompositeScanner);
    }

    /**
    * Return the set of names handled by this tag.
    * @return The names to be matched that create tags of this type.
    */
    public String[] getIds ()
    {
    return (mIds);
    }

    public void doSemanticAction () throws ParserException
    {
    mBuffer.append (getChildren ().toString());
    }
    }

    is there a way by which a tag can be placed on desired position if this situation comes.

     
    • Derrick Oswald

      Derrick Oswald - 2005-09-14

      You could add "TABLE" as a tag ender returned in the list from getEnders (). But it's not generic really. And then you would have to turn back on the composite scanner you have commented out.

       
    • sidhu

      sidhu - 2005-09-15

      Perfect!! thanks a lot .It's working fine.I think i can do it now.

       

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.