title: Parsing an xml response from a url using STAX
body: <p>I am sending a xml request through java code and getting the xml response using the below code:</p>
  
  <pre><code>BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
      StringBuilder sb = new StringBuilder();
      String line = null;
      while ((line = rd.readLine()) != null) {
          sb.append(line + '\n');
      }
  </code></pre>
  
  <p>Now I need to parse the xml response using STAX so I have written a method for parsing:</p>
  
  <pre><code>XMLReader reader = new XMLReader();
  ArrayList&lt;String&gt; List = reader.parse(connection.getInputStream());
  </code></pre>
  
  <p>and in the parse() I have reader = factory.createXMLEventReader(connection.getInputStream());</p>
  
  <p>However I am getting the following error:</p>
  
  <pre><code>javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
  Message: Premature end of file.
  at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:593)
  at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(XMLEventReaderImpl.java:85)
  </code></pre>
  
  <p>Can someone please advise me where I am going wrong here?</p>
  
  <p>Thanks,</p>
  
  <p>swati</p>