title: How to upload and read XML file in servlet along with their tags
body: <p>Please advise me to read the XML file along with their tags. I am able to retrieve the contain of the tags but not the tag name. </p>
  
  <p>Code snippet:</p>
  
  <pre><code>FileItemFactory factory = new DiskFileItemFactory();
  ServletFileUpload upload = new ServletFileUpload(factory);
  
  try {
  
      List&lt;FileItem&gt; fields = upload.parseRequest(request);
      out.println("Number of fields: " + fields.size() + "&lt;br/&gt;&lt;br/&gt;");
      Iterator&lt;FileItem&gt; it = fields.iterator();
      if (!it.hasNext()) {
          out.println("No fields found");
          return;
      }
      out.println("&lt;table border=\"1\"&gt;");
      while (it.hasNext()) {
          out.println("&lt;tr&gt;");
          FileItem fileItem = it.next();
          boolean isFormField = fileItem.isFormField();
          if (isFormField) {
              out.println("&lt;td&gt;regular form field&lt;/td&gt;&lt;td&gt;FIELD NAME: " + fileItem.getFieldName() + "&lt;br/&gt;STRING: " + fileItem.getString());
              out.println("&lt;/td&gt;");
          } else {
              out.println("&lt;td&gt;file form field&lt;/td&gt;&lt;td&gt;FIELD NAME: " + fileItem.getFieldName() +
              "&lt;br/&gt;STRING: " + fileItem.getString() +
              "&lt;br/&gt;NAME: " + fileItem.getName() +
              "&lt;br/&gt;CONTENT TYPE: " + fileItem.getContentType() +
              "&lt;br/&gt;SIZE (BYTES): " + fileItem.getSize() +
              "&lt;br/&gt;TO STRING: " + fileItem.toString() 
              );
  
              out.println("&lt;/td&gt;");
          }
  </code></pre>
  
  <p>XML used :</p>
  
  <pre><code> &lt;?xml version="1.0"?&gt;
   -&lt;students&gt;
  -&lt;student&gt;
   &lt;name&gt;John&lt;/name&gt;
   &lt;grade&gt;B&lt;/grade&gt;
   &lt;age&gt;12&lt;/age&gt;
   &lt;/student&gt;
   -&lt;student&gt;
   &lt;name&gt;Mary&lt;/name&gt;
   &lt;grade&gt;A&lt;/grade&gt;
   &lt;age&gt;11&lt;/age&gt;
   &lt;/student&gt;
   -&lt;student&gt;
   &lt;name&gt;Simon&lt;/name&gt;
   &lt;grade&gt;A&lt;/grade&gt;
   &lt;age&gt;18&lt;/age&gt;
   &lt;/student&gt;
   &lt;/students&gt;
  </code></pre>
  
  <p>Output : </p>
  
  <pre><code> FIELD NAME: Browse
   STRING: - John B 12 Mary A 11 Simon A 18 
   NAME: Samplexml.xml
   CONTENT TYPE: text/xml
   SIZE (BYTES): 313
   TO STRING: name=Samplexml.xml,StoreLocation=C:\Users\Bramesh\AppData\Local\Temp\upload_1aa898c7_7c38_4e32_958b_25efcf0b37c8_00000000.tmp, size=313 bytes, isFormField=false, FieldName=Browse
  </code></pre>