0 Replies Latest reply: Jul 31, 2007 5:23 AM by 807605 RSS

    DOM navigation problem

    807605
      I am trying to navigate a DOM tree so that i can select particular elements from a table data within the tree. The tree is a parsed HTML page.

      When i define the contents of the TD as a NamedNodemap so that i can access the attributes, i am only allowed to assess the attribute value of the first index value i.e. item(0). But when i try to access the next attribute value, i get a null pointer exception!

      The code except below might shine some light:
      int i = 0;
                     
                          org.w3c.dom.Node level17 = level16.item(i);
                          org.w3c.dom.Node final_td = level17.getNextSibling();
                          org.w3c.dom.NamedNodeMap elems =  final_td.getAttributes();
                         
                          
                          
                          System.out.println(elems.item(0).getNodeValue());
      OUTPUT
      run-main:
      images/strback.gif
      BUILD SUCCESSFUL (total time: 1 second)

      THE TABLE DATA

      <td background="images/strback.gif"><img src="images/wtype5.gif"><img src="images/lvlbox2.gif"></td>

      I can access the background attribute value i.e.
      images/strback.gif but when i try accessing any other attribute values e.g. item(1) or item(2) i get the error below:
      Exception in thread "main" java.lang.NullPointerException
              at NewCHORIST.tidyHTML(NewCHORIST.java:152)
              at NewCHORIST.main(NewCHORIST.java:374)
      Java Result: 1
      BUILD SUCCESSFUL (total time: 1 second)
      Any pointers will be very much appreciated!