Feature #1467

Updated by Serge Heiden over 4 years ago

Currently,

A)
the XPathResult.groovy script/class API provides 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

To be able to process large XML files with lots of elements matching 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 to only the one used for the list of DOM result nodes.

B) the getXpathResponse* methods cannot return elements attribute values, for example for XPaths returning attribute values

h3. Solution A)

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>

h3. Solution B)

Check in those methods the type of values returned by the XPath processor.

Back