処理してデータベースに保存したい大きな SOAP 応答があります。以下のように全体を Document として処理しようとしています
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setCoalescing(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(resp.getBytes());
Document doc = db.parse(is);
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile(fetchResult);
String result = (String) expr.evaluate(doc, XPathConstants.STRING);
resp は SOAP 応答で、fetchResult は String fetchResult = "//result/text()"; です。
このアプローチでは、メモリ例外が発生しています。そのため、応答全体をドキュメントとして消費するのではなく、ドキュメントをストリームとして処理しようとしていました。
しかし、私はコードを思い付くことができません。
どなたか助けていただけませんか?