title: could not convert the xml to json using java
body: <p><strong>i have the xml file, i need to convert into the json.
  the json output is the partial convert of the xml, not whole xml is converted..</strong></p>
  
  <p>Reason you can find the output of the json, only partial is being converted.
  remaining portion is omitted.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;ASF_Service_ResponseVO typesig="155c0afe34b" id="1"&gt;
      &lt;service type="String"&gt;OnboardingV2&lt;/service&gt;
      &lt;operation type="String"&gt;start_onboarding_session&lt;/operation&gt;
      &lt;requested_version type="String"&gt;1.0&lt;/requested_version&gt;
      &lt;actual_version type="String"&gt;1.0&lt;/actual_version&gt;
      &lt;server_info type="String"&gt;onboardingv2serv:start_onboarding_session&amp;amp;CalThreadId=85&amp;amp;TopLevelTxnStartTime=13b40fe91c4&amp;amp;Host=L-BLR-00438534&amp;amp;pid=3564&lt;/server_info&gt;
      &lt;result typesig="fff96cab366a5def" type="Onboarding::StartOnboardingSessionResponse" id="2"&gt;
          &lt;onboarding_id type="String"&gt;137&lt;/onboarding_id&gt;
          &lt;success type="bool"&gt;true&lt;/success&gt;
      &lt;/result&gt;
  &lt;/ASF_Service_ResponseVO&gt;
  </code></pre>
  
  <h2>ConvertXMLtoJSON.java</h2>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package javasample1;
  
  //import net.sf.json.JSON;
  //import net.sf.json.JSONObject; 
  //import net.sf.json.xml.XMLSerializer;
  import org.json.JSONObject;
  import org.json.JSONException;
  import org.json.XML;
  import java.io.*;
  /**
   *
   * @author gopc
   */
      public class ConvertXMLtoJSON{
  
          public static void main(String[] args) throws Exception 
          {
              try
              {
  
                  File file = new File ("C:\\Users\\gopc\\Documents\\NetBeansProjects\\JavaSample1\\src\\javasample1\\Sample1.xml");
                  InputStream inputStream = new FileInputStream(file);
                  StringBuilder builder =  new StringBuilder();
                  int ptr = 0;
                  while ((ptr = inputStream.read()) != -1 )
                  {
                      builder.append((char) ptr);
                  }
  
                  String xml  = builder.toString();
                  JSONObject jsonObj = XML.toJSONObject(xml); 
                  System.out.println(jsonObj);
  
                  /*
                  String xmlString  = "&lt;?xml version=\"1.0\"?&gt;&lt;ASF_Service_ResponseVO id=\"1\"&gt;&lt;service type=\"String\"&gt;OnboardingV2&lt;/service&gt;&lt;operation type=\"String\"&gt;start_onboarding_session&lt;/operation&gt;&lt;requested_version type=\"String\"&gt;1.0&lt;/requested_version&gt;&lt;actual_version type=\"String\"&gt;1.0&lt;/actual_version&gt;&lt;server_info type=\"String\"&gt;onboardingv2serv:start_onboarding_session&amp;amp;CalThreadId=85&amp;amp;TopLevelTxnStartTime=13b40fe91c4&amp;amp;Host=L-BLR-00438534&amp;amp;pid=3564&lt;/server_info&gt;&lt;result type=\"Onboarding::StartOnboardingSessionResponse\" id=\"2\"&gt;&lt;onboarding_id type=\"String\"&gt;137&lt;/onboarding_id&gt;&lt;success type=\"bool\"&gt;true&lt;/success&gt;&lt;/result&gt;&lt;/ASF_Service_ResponseVO&gt;";
  
                  JSONObject jsonObj = XML.toJSONObject(xmlString); 
                  System.out.println(jsonObj.toString()); 
                  */
              }
              catch(Exception e)
              {
                  e.printStackTrace();
              }
          }
  }
  </code></pre>
  
  <h2>output</h2>
  
  <pre><code>run:
  {"ASF_Service_ResponseVO":{"server_info":{"content":"onboardingv2serv:start_onboarding_session&amp;CalThreadId=85&amp;TopLevelTxnStartTime=13b40fe91c4&amp;Host=L-BLR-00438534&amp;pid=3564","type":"String"},"result":{"id":2,"typesig":"fff96cab366a5def","onboarding_id":{"content":137,"type":"String"},"type":"Onboarding::StartOnboardingSessionResponse","success":{"content":true,"type":"bool"}},"operation":{"content":"start_onboarding_session","type":"String"},"requested_version":{"content":1,"type":"String"},"service":{"content":"OnboardingV2","type":"String"},"actual_version":{"content":1,"type":"String"}}}
  </code></pre>
  
  <p>BUILD SUCCESSFUL (total time: 0 seconds)</p>
  
  <p>The resulting JSON object formated:</p>
  
  <pre><code>{
      "ASF_Service_ResponseVO": {
          "server_info": {
               "content":"onboardingv2serv:start_onboarding_session&amp;CalThreadId=85&amp;TopLevelTxnStartTime=13b40fe91c4&amp;Host=L-BLR-00438534&amp;pid=3564",
               "type":"String"
          },
          "result": {
              "id":2,
              "typesig":"fff96cab366a5def",
              "onboarding_id": {
                   "content":137,
                   "type":"String"
              },
              "type":"Onboarding::StartOnboardingSessionResponse",
              "success": {
                  "content":true,
                  "type":"bool"
              }
          },
          "operation": {
              "content":"start_onboarding_session",
              "type":"String"
          },
          "requested_version":{
              "content":1,
              "type":"String"
          },
          "service":{
              "content":"OnboardingV2",
              "type":"String"},
          }
          "actual_version":{
               "content":1,
               "type":"String"
          }
      }
  }
  </code></pre>