Menu

About getPreviousSibling() method in New rele

Help
2005-11-30
2013-04-27
  • Shuvadeep Lahiri

    Hi,
    It seems getPreviousSibling() and getNextSibling() methos have been written for convenience. Now I have a very simple web-page like this :

      <html>
    <body>
        <table>   
            <tr>
                    <td height="5">Mongolia</td>
                    <td height="5">Togo</td>
                    <td height="5">Uruguay</td>
            </tr>   
        </table>
    </body>
    </html>

    I have picked a NodeList for all "TD" having height=5 like below:

    try
               { return parser.extractAllNodesThatMatch(new AndFilter(new TagNameFilter("TD"),new HasAttributeFilter("height","5")));
               }catch(ParserException e)
                { 
                      System.out.println("Parsing error "+e);
                      e.printStackTrace ();
                      return null;
                } 

    I have stored this into NodeList list. When I write :
      Node n = (Node)list.elementAt(1);
    System.out.println (n.toHtml ());
    It prints:
      <td height="5">Togo</td>
    So upto this, it is perfect. But whenever I write
     
      Node m = n.getPreviousSibling ();
    System.out.println (m.toHtml ());
    I was expecting it should print : <td height="5">Mongolia</td> ; but it prints nothing. Same is the case for getNextSibling() method.
       Can anyone suggest whether I am making any mistake? What is the way to print as I wish?
      Shuvadeep

     

      

     
    • Derrick Oswald

      Derrick Oswald - 2005-11-30

      All nodes (even whitespace text) are in the children list. I believe you are seeing nothing because you are printing out the TextNode containing "\n                " bewteen the Mongolia and Togo table column elements.

       
    • Shuvadeep Lahiri

      Thank you. It does print <td height="5">Mongolia</td> properly now.
                Just a small question. Suppose my NodeList only contain <td height="5">Togo</td>. Could it print the same <td height="5">Mongolia</td> by using getPreviousSibling() method?

      Shuvadeep

       
      • Derrick Oswald

        Derrick Oswald - 2005-11-30

        Yes. Items in the nodelist are still fully linked via the children lists.

        You could have just tried it, no?

         

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.