title: Convert String to XML Document without changing end tag
body: <p>I use Axis to get some response through a remote Web Service.
  After receiving the response, I would convert the response string to XML Document in order for the subsequent process.
  Finally, my program would convert the processed Document to String as return.</p>
  
  <p>Sometime I would receive some tag like <code>&lt;bla&gt;&lt;/bla&gt;</code>, a pair of tag with nothing.
  After converting the String to Document and getting through the process, the result would be converted to String finally.</p>
  
  <p>But the <code>&lt;bla&gt;&lt;/bla&gt;</code> would become <code>&lt;bla/&gt;</code> automatically.</p>
  
  <p>How do I keep the <code>&lt;bla&gt;&lt;/bla&gt;</code> the same without any change?</p>
  
  <p>The following code is what I used to do the conversion. </p>
  
  <pre><code>public class TagMove {
     public static void main(String[] args)  throws Exception {
         String strA = "&lt;STUDENT&gt;&lt;NAME&gt;Arthur&lt;/NAME&gt;&lt;AGE&gt;&lt;/AGE&gt;&lt;/STUDENT&gt;";
         Document docA = convertStringToDocument(strA, "UTF8");
         docA.setXmlStandalone(true);
         System.out.println(convertDocument2String(docA));
     }
  
     public static String convertDocument2String(Document doc) throws Exception {
         TransformerFactory tf = TransformerFactory.newInstance();
         Transformer transformer = tf.newTransformer();
         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
         StreamResult result = new StreamResult(new StringWriter());
         DOMSource source = new DOMSource(doc);
         transformer.transform(source, result);
         String xmlString = result.getWriter().toString();
         return xmlString;
     }
     public static Document convertStringToDocument(String xmlString, String encoding) {
         try {
             DocumentBuilderFactory FACTORY =    DocumentBuilderFactory.newInstance();
             DocumentBuilder builder = FACTORY.newDocumentBuilder();
             Document doc = builder.parse(new InputSource(new ByteArrayInputStream(xmlString.getBytes(encoding))));
             return doc;
         } catch (Exception e) {
             e.printStackTrace();
         }
         return null;
     }
  }
  </code></pre>