Feature #1467
Mis à jour par Serge Heiden il y a presque 10 ans
Currently, The getXpathResponse method of the XPathResult.groovy script/class API provides XPathResult class returns only two 'all in memory' model methods:
* getXpathResponse returns the first match of an XPath
* getXpathResponses returns all the string values of the matches of an XPath as an array of strings XPath.
To be able to process large XML files with lots of elements matching Add a given XPath, we need to add to the API a way not to store the intermediate array of strings in memory. The new method can limit the memory consumption used to transmit the result XPathResult class implementing an iterator to only successively retrieve all the one used for the list matches of DOM result nodes.
h3. Solution
Add a new streamingGetXpathResponses method with the code of getXpathResponses where:
<pre>
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
//println nodes.item(i)
xresult.add((nodes.item(i).getNodeValue()));
}
return xresult
</pre>
is replaced by:
<pre>
NodeList nodes = (NodeList) result
return nodes
</pre>
The Groovy code calling streamingGetXpathResponses can then iterate the results with:
<pre>
nodes.each { println it.getNodeValue() }
</pre> an XPath.
* getXpathResponse returns the first match of an XPath
* getXpathResponses returns all the string values of the matches of an XPath as an array of strings XPath.
To be able to process large XML files with lots of elements matching Add a given XPath, we need to add to the API a way not to store the intermediate array of strings in memory. The new method can limit the memory consumption used to transmit the result XPathResult class implementing an iterator to only successively retrieve all the one used for the list matches of DOM result nodes.
h3. Solution
Add a new streamingGetXpathResponses method with the code of getXpathResponses where:
<pre>
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
//println nodes.item(i)
xresult.add((nodes.item(i).getNodeValue()));
}
return xresult
</pre>
is replaced by:
<pre>
NodeList nodes = (NodeList) result
return nodes
</pre>
The Groovy code calling streamingGetXpathResponses can then iterate the results with:
<pre>
nodes.each { println it.getNodeValue() }
</pre> an XPath.