title: Trouble parsing xml in large Inputstream
body: <p>I am running a query through an API and I'm receiving a larger set of XML through an InputStream than I normally expect. This is causing me to run into heap space errors while trying to parse the XML into a String. Here is how I am currently parsing the input stream:</p>
  
  <pre><code>public String parseXml(InputStream inputStream) throws IOException {
      String myString;
      List&lt;String&gt; matchingXmlList = new ArrayList&lt;&gt;();
      byte[] byteArray = toByteArray(inputStream);
      String tempString = new String(byteArray, StandardCharsets.UTF_8);
      return tempString;
  }
  </code></pre>
  
  <p>Under normal circumstances, this is the output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"&gt;
    &lt;queryResult&gt;
      &lt;records /&gt;
      &lt;records /&gt;
      &lt;records /&gt;
      &lt;records /&gt;
    &lt;/queryResult&gt;
  </code></pre>
  
  <p>After receiving an output like this, I then use a Matcher to parse each individual records node and add it to a List of Strings. But when the InputStream is too large, I run into memory problems when trying to put the InputStream into a String.</p>
  
  <p>Is there a way to parse the InputStream without running into memory problems? I need to be able to parse each individual records element to a string of XML.</p>