benibela / internettools

XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, pattern matching, XML/HTML/JSON parsers and classes for HTTP/S requests
http://www.benibela.de/sources_en.html#internettools
122 stars 35 forks source link

Possible issue with enumerator ? #3

Closed zbyna closed 9 years ago

zbyna commented 9 years ago

Hi, thanks for this great library. :clap: I had something like small issue with finishing enumerator after proceeding the first item:

    i:=0;
    for  v in process(str,'for $pr in jn:parse-json(.)("results")()' +
                          'return [$pr("title"), $pr("release_date") ]') do
      begin
         pomString := (v as TXQValueJSONArray).seq.get(0).toString; 
         pomString3:= (v as TXQValueJSONArray).seq.get(1).toString;
         Memo1.Append((inttostr(i))+' '+(pomString) + ' :-) '+ pomString3);
         i:=i+1;
     end;

after splitting the code enumerator passed through all items:

    p, p3: IXQValue;
    i:=0;
    for  v in process(str,'for $pr in jn:parse-json(.)("results")()' +
                          'return [$pr("title"), $pr("release_date") ]') do
      begin
          p :=(v as TXQValueJSONArray).seq.get(0);
          p3:=(v as TXQValueJSONArray).seq.get(1);
          pomString3:= p3.toString;
          pomString:=p.toString;
          Memo1.Append((inttostr(i))+' '+(pomString) + ' :-) '+ pomString3);
          i:=i+1;
     end;
benibela commented 9 years ago

fixed

Actually no for-in-process worked reliable.

You had to do it with another variable:

w := process(str,'for $pr in jn:parse-json(.)("results")()' +
                      'return [$pr("title"), $pr("release_date") ]');
for  v in w do ...

Also, is str JSON or JSON in XML? Because former was changed from the jn:parse-json(.)("results") syntax to $json("results")

(Also, you never need a for loop if there is only a single variable You can write it as ("results")() ! [ .("title"), .("release_date") ])