Blank result for a long GREL expression parsing XML data

Hi everyone,

I am parsing XML data with a long GREL expression, but while the preview shows the result I expect, the column produced has only blank cells. Do you have an idea of why?

I am starting with data like "SDC 12-4142", then harvesting an API by using this URL:

https://catalogue.bnf.fr/api/SRU?version=1.2&operation=searchRetrieve&query=bib.cote%20adj%20"SDC+12-4142"&recordSchema=unimarcxchange&maximumRecords=20&startRecord=1

Then I get the XML and try to parse it in a new column by applying this GREL expression:

forEach(value.parseXml().select("mxc|record"),record, if(startsWith(record.select("mxc|datafield[tag=930]")[0].select("mxc|subfield[code=a]")[0].xmlText(), "SDC"),record.select("mxc|datafield[tag=215]")[0].select("mxc|subfield[code=a]")[0].xmlText(), None)).join(" | ")

In the preview, the result I expect ("2 disques compacts | 1 disque compact (55 min 19 s)") shows up but when I click OK the column is blank.

I noticed the same behavior with v. 3.7.2 and v. 3.7.6.

Thank you for any help you could give me and sorry if a similar question was already asked!

Bertrand Caron

The most common reason for the type of behavior that you describe is
that the preview window is showing an array, which OpenRefine can't
store in a cell, but I just tried your expression with OpenRefine
3.7.6 and it worked fine for me.

Here's what I did:

  • Created a project from the clipboard and pasted your URL into the window
  • Used Add column by fetching URL to get the XL
  • Used Add column based on this column with your GREL expression
  • Confirmed that it produced your desired result.

On the other hand, if I leave of the final join('|'), the preview
window shows [ "2 disques compacts", "1 disque compact (55 min 19 s)"
] which is an array that's not storable (we should probably highlight
this fact a little better in the preview window).

Tom

Thank you very much @tfmorris . I was told about this issue with arrays earlier, but adding join() did not seem to help.

After reading your answer, I switched to my personal computer and it worked. Don't know why, but it doesn't matter really.

Thanks again!

Glad to help. It is a problematic design which has been around forever, unfortunately. The first time it was discussed was 2011.

https://github.com/OpenRefine/OpenRefine/issues/434

https://github.com/OpenRefine/OpenRefine/issues/443

https://github.com/OpenRefine/OpenRefine/issues/1088

https://github.com/OpenRefine/OpenRefine/issues/1475

https://github.com/OpenRefine/OpenRefine/issues/4823

There is a similar issue with other unstorable intermediary types (JSON object, XML elements).
We need a better mechanism for signalling to the user that these are not storable in a cell.

Tom