title: How to read the content of sub tag along with the parent tag of XML in java
body: <p>I am new to Java and am trying to write a program that gets the meaning of a given word from MW api. The output is XML, now I am using DOM parser to print the list of all definitions. Normally the retrieved XML will be as following</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;entry_list version="1.0"&gt;
      &lt;entry id="dictionary"&gt;&lt;ew&gt;dictionary&lt;/ew&gt;&lt;subj&gt;PU-1#PU-2#PU-3#CP-4&lt;/subj&gt;&lt;hw&gt;dic*tio*nary&lt;/hw&gt;&lt;sound&gt;&lt;wav&gt;dictio04.wav&lt;/wav&gt;&lt;/sound&gt;&lt;pr&gt;Ëˆdik-shÉ™-ËŒner-Ä“, -ËŒne-rÄ“&lt;/pr&gt;&lt;fl&gt;noun&lt;/fl&gt;&lt;in&gt;&lt;il&gt;plural&lt;/il&gt; &lt;if&gt;dic*tio*nar*ies&lt;/if&gt;&lt;/in&gt;&lt;et&gt;Medieval Latin &lt;it&gt;dictionarium,&lt;/it&gt; from Late Latin &lt;it&gt;diction-, dictio&lt;/it&gt; word, from Latin, speaking&lt;/et&gt;&lt;def&gt;&lt;date&gt;1526&lt;/date&gt; &lt;sn&gt;1&lt;/sn&gt; &lt;dt&gt;:a reference source in print or electronic form containing words usually alphabetically arranged along with information about their forms, &lt;d_link&gt;pronunciations&lt;/d_link&gt;, functions, &lt;d_link&gt;etymologies&lt;/d_link&gt;, meanings, and &lt;d_link&gt;syntactical&lt;/d_link&gt; and idiomatic uses&lt;/dt&gt; &lt;sn&gt;2&lt;/sn&gt; &lt;dt&gt;:a reference book listing alphabetically terms or names important to a particular subject or activity along with discussion of their meanings and &lt;d_link&gt;applications&lt;/d_link&gt;&lt;/dt&gt; &lt;sn&gt;3&lt;/sn&gt; &lt;dt&gt;:a reference book listing alphabetically the words of one language and showing their meanings or translations in another language&lt;/dt&gt; &lt;sn&gt;4&lt;/sn&gt; &lt;dt&gt;:a &lt;d_link&gt;computerized&lt;/d_link&gt; list (as of items of data or words) used for reference (as for information retrieval or word processing)&lt;/dt&gt;&lt;/def&gt;&lt;/entry&gt;
  &lt;/entry_list&gt;
  </code></pre>
  
  <p>The list of definitions will be enclosed inside the tag <code>&lt;dt&gt;</code> </p>
  
  <p>Now the problem I am facing is inside the tag <code>&lt;dt&gt;</code> there is another sub tag <code>&lt;d_link&gt;</code>. Whenever the DOM parser runs across this sub tag, the <code>getNodeValue()</code> method is considering the end of the tag <code>&lt;dt&gt;</code> </p>
  
  <p>My Code is as below:</p>
  
  <pre><code>import org.w3c.dom.*;
  import javax.xml.parsers.*;
  
  public class Dictionary5 {
      public static void main(String[] args) throws Exception {
          String head = new String("http://www.dictionaryapi.com/api/v1/references/collegiate/xml/");
          String word = new String("banal");
          String apiKey = new String("?key=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"); //My API Key for Merriam webster
          String finalURL = head.trim() + word.trim()+ apiKey.trim();
          try
          {
              DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
              DocumentBuilder b = f.newDocumentBuilder();
              Document doc = b.parse(finalURL);
  
              doc.getDocumentElement().normalize();
  
              NodeList items = doc.getElementsByTagName("entry");
              for (int i = 0; i &lt; items.getLength(); i++)
              {
                  Node n = items.item(i);
  
                  if (n.getNodeType() != Node.ELEMENT_NODE)
                      continue;
  
                  Element e = (Element) n;
                  NodeList titleList = e.getElementsByTagName("dt");
                  for (int j = 0; j &lt; titleList.getLength(); j++){
                      Node dt = titleList.item(j);
                      if (dt.getNodeType() != Node.ELEMENT_NODE)
                          continue;                   
                      Element titleElem = (Element) titleList.item(j);
                      Node titleNode = titleElem.getChildNodes().item(0);
                      System.out.println(titleNode.getNodeValue());
                  }
              }
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p>The output is as following</p>
  
  <pre><code>:a reference source in print or electronic form containing words usually alphabetically arranged along with information about their forms, 
  :a reference book listing alphabetically terms or names important to a particular subject or activity along with discussion of their meanings and 
  :a reference book listing alphabetically the words of one language and showing their meanings or translations in another language
  :a 
  </code></pre>
  
  <p>As you can see the first, second and fourth definitions are abruptly ended because the parser encounter the sub tag <code>&lt;d_link&gt;</code>. </p>
  
  <p>My Expected output is as following:</p>
  
  <pre><code>:a reference source in print or electronic form containing words usually alphabetically arranged along with information about their forms, pronunciations, functions, etymologies, meanings, and syntactical and idiomatic uses
  :a reference book listing alphabetically terms or names important to a particular subject or activity along with discussion of their meanings and applications
  :a reference book listing alphabetically the words of one language and showing their meanings or translations in another language
  :a computerized list (as of items of data or words) used for reference (as for information retrieval or word processing)
  </code></pre>
  
  <p>Can someone please help me with this. Any help is highly appreciated. Thanks in advance.</p>