defining array variable in web-harvest

1.3k views Asked by At

I'm using Web-Harvest to extract some data from a site.
Site gets a POST variable named Code and gives data according to it.
The available codes are gathered from another page of that site.
How Can I define an array like variable to store those data that are related to a Code in a array like variable that make me able to retrieve them with a loop in main program?
I mean something like this:

Data[code1]={key1=val1, key2=val2, key3=val3,...}
Data[code2]={key1=val1, key2=val2, key3=val3,...}
Data[code3]={key1=val1, key2=val2, key3=val3,...}
Data[code4]={key1=val1, key2=val2, key3=val3,...}
...
1

There are 1 answers

0
Paker On BEST ANSWER

You can use <script> tag and build an array inside it using BeanShell, Groovy or JavaScript. Default is BeanShell.

Then expose it to your script with SetContextVar() method or return attribute of the <script>.

Below is example that builds an array of strings codes and then iterates through them with <loop>.

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <script><![CDATA[
            String[] codes = new String[] {"one", "two", "three"};
            SetContextVar("codes", codes);
        ]]></script>

    <loop item="code">
        <list>
            <var name="codes" />
        </list>
        <body>
            <var name="code" />
        </body>
    </loop>
</config>

Read more about <script> in the Web-Harvest manual.