title: Java XML parsing using DOM to get nodevalue
body: <pre><code>    try {
          String data = "&lt;a&gt;&lt;b c='d' e='f'&gt;0.15&lt;/b&gt;&lt;/a&gt;";
          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                  .newInstance();
          DocumentBuilder documentBuilder = documentBuilderFactory
                  .newDocumentBuilder();
          InputSource is = new InputSource();
          is.setCharacterStream(new StringReader(data));
          Document document = documentBuilder.parse(is);
  
          NodeList nl = document.getElementsByTagName("b");
          Node n = (Node) nl.item(0);
          System.out.println(n.getNodeValue());
      } catch (Exception e) {
          System.out.println("Exception " + e);
  
      }
  </code></pre>
  
  <p>I am expecting it to print 0.15, but it prints null. Any Ideas?</p>
  
  <p>Edit: This did the trick</p>
  
  <pre><code>        if (n.hasChildNodes())
              System.out.println(n.getFirstChild().getNodeValue());
          else 
              System.out.println(n.getNodeValue());
  </code></pre>