title: How can I parse String containing XML tags , so that I can get value of all the sub tags
body: <p>I have to parse a String containing XML tags like the one hard coded below so that I can get values of all the tags separately. Here when I am using </p>
  
  <pre><code>NodeList node = doc.getElementsByTagName("event");
  </code></pre>
  
  <p>It is returning value as "ajain1AnkitJain24-04-199223:09.08"</p>
  
  <p>I want to retrieve value for each tag and store it separately in different variables.</p>
  
  <p>Like for eg in this scenario I want to Store Value as :</p>
  
  <pre><code>String UID = ajain1
  String FirstName = Ankit
  String LastName = Jain
  Date date = "24-04-1992 23:09.08"
  </code></pre>
  
  <p>Here is the Sample code I am working on.</p>
  
  <pre><code>package test;
  
  import java.io.IOException;
  import java.io.StringReader;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  public class Demo {
  
      public static void main(String[] args) {
  
          String xmldata = "&lt;event&gt;&lt;class&gt;&lt;/class&gt;&lt;data&gt;&lt;UID&gt;&lt;![CDATA[ajain1]]&gt;&lt;/UID&gt;&lt;FIRSTNAME&gt;&lt;![CDATA[Ankit]]&gt;&lt;/FIRSTNAME&gt;&lt;LASTNAME&gt;&lt;![CDATA[Jain]]&gt;&lt;/LASTNAME&gt;&lt;DATE&gt;&lt;![CDATA[24-04-1992]]&gt;&lt;/DATE&gt;&lt;TIME&gt;&lt;![CDATA[23:09.08]]&gt;&lt;/TIME&gt;&lt;/data&gt;&lt;/event&gt;";
  
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = null;
          try {
              db = dbf.newDocumentBuilder();
              InputSource is = new InputSource();
              is.setCharacterStream(new StringReader(xmldata));
              try {
                  Document doc = db.parse(is);
                  //String message = doc.getDocumentElement().getTextContent();
                  //System.out.println(message);
  
                  NodeList node = doc.getElementsByTagName("event");
  
              } catch (SAXException e) {
                  // handle SAXException
              } catch (IOException e) {
                  // handle IOException
              }
          } catch (ParserConfigurationException e1) {
              // handle ParserConfigurationException
          }
          // TODO Auto-generated method stub
      }
  }
  </code></pre>
  
  <p>Thanks and let me know if you require any more information.</p>