title: Best way to transfer XML data between server and client sockets
body: <p>Server side:</p>
  
  <pre><code>PrintWriter outputStream = new PrintWriter(client.getOutputStream(),true);
  BufferedReader inputStream = new BufferedReader(newInputStreamReader(client.getInputStream()));
  outputStream.println("hello client");
  System.out.println("server got: " + inputStream.readLine());
  outputStream.println("to the client");
  </code></pre>
  
  <p>Client Side:</p>
  
  <pre><code>try{
      serverSocket = new Socket("machineName", 4444);
      out = new PrintWriter(serverSocket.getOutputStream(), true);
      in = new BufferedReader(new InputStreamReader(serverSocket.getInputStream()));
  }
  catch(Exception e){
      e.printStackTrace();
  }
  
  if ((fromServer = in.readLine()) != null) {
      System.out.println("Server: " + fromServer);
      fromUser = "I am the user";
      out.println(fromUser);
      System.out.println("Server: " + in.readLine());
  }
  </code></pre>
  
  <p><p> I am using this format for communicating between server and client sockets. Now I would like to send XML between client and server instead of strings. I have used DOM to parse XML data on server and client side.</p>
     <p>Is there an efficient way to transfer XML between client and server instead of converting the XML to string and removing newline (because readLine reads one line at a time and XML start tag &amp; end tag wont come in a single line in XML format) from XML data and sending it to client through Printwriter. </p></p>
  
  <p>Thanks </p>
  
  <p>P.S: This is not a homework question. I am learning java sockets for interviews. </p>